Telerik RadGrid doesn’t display on first Page_Load but does on postback

asp.netpageloadradgridtelerik

I have a page with a drop-down. Based on the selection in the drop-down, data gets loaded and populates a RadGrid. I am using a custom user control for the EditTemplate, so I can't use radGrid.DataBind(). Instead, I have to use radGrid.MasterTableView.Rebind() in association with a NeedDataSource event handler.

My problem is that when I load the page initially, I populate the drop-down and automatically select a value (first item in the list) which triggers the databinding on the RadGrid. I can step through the code in debug mode and see that the grid is being populated with data, but when the page displays, it doesn't get rendered. When I then manually choose an item from the drop-down, which triggers the same grid databinding code, it displays properly the second time.

How do I get it to display the grid the first time the page loads?

Best Answer

I have a very similar issue with nested Multipage with RadGrid in RadGrid

aspx:

<telerik:RadTabStrip><Tabs><!-- ... --></Tabs></telerik:RadTabStrip>
<telerik:RadMultiPage>
<telerik:RadPageView>

<!-- ChildRadGrid1 doesn't display on first time but does on postback --> 
<telerik:RadGrid ID="ChildRadGrid1"><!-- ... --></telerik:RadGrid>

<telerik:RadPageView>
</telerik:RadMultiPage>
</NestedViewTemplate>

<!-- Columns... -->

</MasterTableView>
</telerik:RadGrid>

In my case, only Rebind() in ItemCommand of parent grid helps me:

aspx.cs:

class MyPage : Page
{
  protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e)
  {
    if (e.CommandName == RadGrid.ExpandCollapseCommandName && e.Item is GridDataItem)
    {
      var dataItem = e.Item as GridDataItem;

      // rebiding fix situation    
      (dataItem.ChildItem.FindControl("ChildRadGrid1") as RadGrid).Rebind();
    }
  }
}
Related Topic