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

Hide Row not working

1 Answer 66 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Robert
Top achievements
Rank 1
Robert asked on 19 Jul 2012, 09:43 PM
I have a situation similar to this.  In my case, I have a DataTable with pairs of companion rows.  When first presented to the user. every second row (the latter of the pair) needs to be hidden.  Then if the user checks a checkbox, its companion row below it will be displayed.

From the Page_PreRender event handler, I call a method that populates the DataTable. Then later in that method it is bound to the RadGrid thusly:

      radGrid.DataSourceID = null;<br>      radGrid.DataSource = dataTable;<br>      radGrid.DataBind();<br>

Also defined is an ItemDataBound event handler.  Here's the beginning of it:

    protected void radGrid_ItemDataBound(object sender, GridItemEventArgs e)<br>    {<br>      if (e.Item is GridDataItem)<br>      {<br>        GridDataItem item = (GridDataItem)e.Item;<br>

I then used assorted logic within the ItemDataBound event handler to determine whether the given row should be hidden.  I do so with this statement:
                                item.Visible = false;

The statement is definitely executed and the visibility of 'item' is definitely set to 'false'.  But yet, when the screen appears, no rows are hidden.

What am I doing wrong?

Robert

P.S. Note: Back in the method called from Page_PreRender, right after radGrid.DataBind() I added this code as a test:

        foreach (GridDataItem item in radGrid.Items)<br>        {<br>          if ((item.ItemIndex % 2) == 1)<br>            item.Visible = false;<br>        } <br>

And lo and behold, it worked!  BUT I sure would love an explanation as to why my original approach did not!





1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 20 Jul 2012, 06:07 AM
Hello Robert,

The PagePrender event fires after the control's events are raised. So ItemDataBound event will fire before the PagePrender. If you want to hide the items in this event, you should bind the radgrid in PageLoad which fires before PagePrender event.
C#:
protected void Page_Load(object sender, EventArgs e)
{
    RadGrid1.DataSourceID = "SqlDataSource1";
    RadGrid1.DataBind();
}
protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
{
  if (e.Item is GridDataItem)
   {
     GridDataItem item = (GridDataItem)e.Item;
      item.Display = false;
  }
}
Also check this article which explains page life cycle.

Thanks,
Shinu.

Tags
Grid
Asked by
Robert
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Share this question
or