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:
Also defined is an ItemDataBound event handler. Here's the beginning of it:
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:
And lo and behold, it worked! BUT I sure would love an explanation as to why my original approach did not!
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!