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

Conditional display: ItemDataBound vs PreRender

1 Answer 345 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jay
Top achievements
Rank 3
Iron
Iron
Veteran
Jay asked on 20 Dec 2011, 05:28 PM
I'm new to the grid so please bear with me. I've got a GridTemplateColumn which I'm using to display an image.
<telerik:GridTemplateColumn HeaderText="Address" UniqueName="Address" ItemStyle-Width="20">
    <ItemTemplate>
        <a href='<%# Eval("Address") %>' title='<%# Eval("Address") %>'><img src="images/go.gif" border="0" width="33"></a>
    </ItemTemplate>
</telerik:GridTemplateColumn >
This shouldn't be visible if the data is empty, so in the ItemDataBound method, I did
Dim item As GridDataItem = CType(e.Item, GridDataItem)
If condition Then
    item("Address").Controls(0).Visible = False
End If
And this worked just fine under FireFox. But with IE8, it doesn't. Instead, I had to move this to the PreRender method where I had to iterate through the items with the same logic to get it to work. And this approach also works fine under FireFox too, so that's good.

But since I'm new to the grid, I'm wondering, is there a "correct" or recommended place to do this kind of logic? I initially went with the ItemDataBound because that's where similar approaches that I'd found (e.g. here ) had done it. But that obviously didn't work for me with IE8.

1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 21 Dec 2011, 06:00 AM
Hello Jay,

The RadGrid event sequence is as explained in this documentation.
Event sequence.
ItemDataBound event fires when controls are bound to radgrid. One better approach is to hide the column in prerender event as shown below.
C#:
protected void RadGrid1_PreRender(object sender, EventArgs e)
{
  RadGrid1.MasterTableView.GetColumn("Address").Visible = false;
}

-Shinu.
Tags
Grid
Asked by
Jay
Top achievements
Rank 3
Iron
Iron
Veteran
Answers by
Shinu
Top achievements
Rank 2
Share this question
or