views:

732

answers:

1

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?

A: 

I can't answer WHY it was happening, but the solution that works for me is to bind the grid to an ObjectDataSource.

<asp:ObjectDataSource ID="gridData" runat="server"/>

I was already binding the grid to a property on the page which was a collection of type List:

protected List<EquipmentGridItem> GridItems { get; set; }

In order to use the ObjectDataSource, I created a wrapper method to return the list.

public object GetGridData()
{
    return GridItems;
}

Then I bound the grid to the object data source.

protected override void OnInit(EventArgs e)
{
    base.OnInit(e);

    grdUnits.DataSourceID = "gridData";
    gridData.TypeName = typeof (ReservationEdit).ToString();
    gridData.SelectMethod = "GetGridData";
}

Kind of a convoluted solution, but it works.

Mark