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

Reinitializing property values on rebind

2 Answers 35 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Anne Chinn
Top achievements
Rank 1
Anne Chinn asked on 23 Oct 2010, 12:47 AM
I have a RadGrid with a GridTemplateColumn that contains a UserControl that contains another RadGrid. In ItemCreate on the top-level grid (and I have also tried ItemDataBound) I set two properties on the nested grid.

 

protected void StudentGrid_ItemDataBound(object sender, GridItemEventArgs e)

 

{

 

if (e.Item is GridDataItem)

 

{

 

GridDataItem gdi = (GridDataItem)e.Item;

 

 

StudentTasksGrid grid = (StudentTasksGrid)gdi.FindControl("TaskGrid");

 

grid.StudentId =

Convert.ToInt64(gdi.GetDataKeyValue("COEUserID"));

 

grid.ContentArea = (

ContentAreaType)Convert.ToInt32(gdi.GetDataKeyValue("COEContentAreaTypeID"));

 

...
}

Inside the nested grid it's NeedDataSource event uses the ContentArea property to construct its query.

What I am having trouble with is refreshing the top-level grid (which I need to do after a separate dialog window closes). Currently I am calling the code-behind through

 

function refreshGrid(sender, eventArgs) {

 

$find(

"ctl00_MainContent_RadAjaxManager1").ajaxRequest("Rebind");

 

}


which resets the DataSource and call DataBind(). When I do this the nested grid's NeedsDataSource gets call before the top-level grid's ItemDataBound event gets called and so it doesn't have the value of the ContentArea to use in its query.

Can you suggest how I am supposed to refresh the top-level grid and make sure those properties are reset on the nested grid?

Thanks in advance,

Anne

2 Answers, 1 is accepted

Sort by
0
Anne Chinn
Top achievements
Rank 1
answered on 23 Oct 2010, 01:17 AM
I have investigated further...

On the first call to NeedDataSource on the top-level grid it call ItemCreated on the top-level grid for each row in the grid before calling NeedDataSource on the nested grid.

But on the rebind call to NeedDataSource on the top-level grid it calls ItemCreated only for the CommandItem, the Header, and a Filtering one that I don't remember the type, and then it calls NeedDataSource on the nested grid, and then continues calling ItemCreated on the top-level grid.
0
Iana Tsolova
Telerik team
answered on 27 Oct 2010, 11:56 AM
Hello Anne,

You can try getting the desired key values directly in the nested grid NeedDataSource event handler instead. Your code should resemble the below:

protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
{
    RadGrid grid = sender as RadGrid;
    string contentArea = (grid.NamingContainer as GridDataItem).GetDataKeyValue("COEContentAreTypeID");  //you can debug and insure that the naming container of the grid is the parent grid item
}

Check it out and let me know if it works for you.

Regards,
Iana
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
Grid
Asked by
Anne Chinn
Top achievements
Rank 1
Answers by
Anne Chinn
Top achievements
Rank 1
Iana Tsolova
Telerik team
Share this question
or