This is a migrated thread and some comments may be shown as answers.

RadGrid visible property on server and client side

3 Answers 749 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Prathibarani
Top achievements
Rank 1
Prathibarani asked on 27 Aug 2013, 05:01 PM
Hi,
We are using RadGrid with ASP.NET. My grid has templated column with textbox. When the page loads, I am populating Templated column Textbox with the amount that comes from database. Not all rows will have amount. For example, if my grid has 10 rows, only 3 rows may have amount. So, when the page load on client side I have routine that checks for amount in textbox. If it is empty, then hides the row like this:
function GridCreated(sender, eventArgs) {
  //loop thru grid rows and hide the row
  var inputElem = MasterTable.get_dataItems()[i].findElement("txtBoxAmount");
   if (inputElem.value > 0)
      MasterTable.get_dataItems()[i].set_visible(true);
   else
      MasterTable.get_dataItems()[i].set_visible(false);
}
  
  
This code is working fine and hiding row. After all work is done, when the user clicks on 'Submit' button,
Then in my routine on server side, I need to check for visibility property and then get the amounts like this:
foreach (GridDataItem row in rgdAccounts.Items)
            {
                if (row.Visible)
                {//Account is part of the selected template (row is visible).
                    string value = ((TextBox)row.FindControl("txtBoxAmount")).Text;
                     if (value == "")
                        value = "0.00";
                    if (value != "0.00")
                        //Get the amount
           }
 }
  
This check for visibility is alwasy true, even though rows are hidden. So, from this what I understand is that
if rows are hidden on clientside using client side logic, when page gets posted, that won't be taken into
considertation on server side. 
I am not using 'NEED Datasource' event for binding, because for our
architecture, it will not suite to use it. So, I am binding the grid when ever is required. 
Please let me know how to take care of this situation.
  
Thanks,
Prathiba.

3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 28 Aug 2013, 11:14 AM
Hi Prathibarani,

As you said,the hidden rows are not hidden in the server side,when hiding from clientside.Another suggestion would be to do all the coding from serverside.You can hide the rows in ItemDataBound event of the radgrid.Please try the following code snippet.

C#:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
   {
       if (e.Item is GridDataItem)
       {
           GridDataItem item = (GridDataItem)e.Item;
           TextBox txt = (TextBox)item.FindControl("txtBoxAmount");//Access template textbox in view mode
           if (txt.Text == "")//Here set condition to hide row
           {
            item.Display = false;
           }
       }
//Your Submit Button Code
protected void SubmitBtn_Click(object sender, EventArgs e)
   {
       foreach (GridDataItem row in RadGrid1.Items)
       {
        if (row.Display)
        {
          //Your code
        }
       }    
   }

Thanks,
Princy
0
Prathibarani
Top achievements
Rank 1
answered on 28 Aug 2013, 04:17 PM
Thanks Princy for the response. It is not only setting visible property ones because we provided the user with checkbox to show all the rows or only rows with amount. So, there will be a toggling when ever user checks or unchecks checkbox. We don't want to do post back on every check or uncheck. That is why we did that show or hide rows on client side.
  
Thanks,
Prathiba
0
Princy
Top achievements
Rank 2
answered on 29 Aug 2013, 10:05 AM
Hi Prathibarani,

I'm afraid its not possible to get the display hidden in client side to server side,you will have to write the entire code in server side. Since you want to avoid postback,one suggestion would be to ajaxify the RadGrid. Please try the below code snippet.

ASPX:
<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
         <AjaxSettings>
             <telerik:AjaxSetting AjaxControlID="SubmitBtn">
                 <UpdatedControls>
                     <telerik:AjaxUpdatedControl ControlID="RadGrid1"></telerik:AjaxUpdatedControl>
                 </UpdatedControls>
             </telerik:AjaxSetting>
         </AjaxSettings>
         <AjaxSettings>
             <telerik:AjaxSetting AjaxControlID="RadGrid1">
                 <UpdatedControls>
                     <telerik:AjaxUpdatedControl ControlID="RadGrid1"></telerik:AjaxUpdatedControl>
                 </UpdatedControls>
             </telerik:AjaxSetting>
         </AjaxSettings>
</
telerik:RadAjaxManager>
<asp:Button ID="SubmitBtn" runat="server" Text="Submit" OnClick="SubmitBtn_Click" />
<telerik:RadGrid ID="RadGrid1" runat="server" OnItemDataBound="RadGrid1_ItemDataBound">
    <MasterTableView DataKeyNames="OrderID" >
        <Columns>
            <telerik:GridBoundColumn UniqueName="OrderID" DataField="OrderID" HeaderText="OrderID" />        
            <telerik:GridTemplateColumn DataField="OrderDate" HeaderText="OrderDate" UniqueName="OrderDate">
                <ItemTemplate>
                    <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("OrderDate") %>'></asp:TextBox>
                </ItemTemplate>
            </telerik:GridTemplateColumn>
        </Columns>
    </MasterTableView>  
</telerik:RadGrid>

C#:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
  {
      if (e.Item is GridDataItem)
      {
          GridDataItem item = (GridDataItem)e.Item;
          TextBox txt = (TextBox)item.FindControl("TextBox1");//Access template textbox in view mode
          if (txt.Text == "")//Your Conditoin to Hide a Row
          {
              item.Display = false;
          }
      }
  }
  protected void SubmitBtn_Click(object sender, EventArgs e)
  {
     foreach (GridDataItem item in RadGrid1.MasterTableView.Items)
      {
          if (item.Display)
          {
              //Your Code
          }
      }     
  }


Thanks,
Princy
Tags
Grid
Asked by
Prathibarani
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Prathibarani
Top achievements
Rank 1
Share this question
or