Hi. I have a parent grid and a child grid below. If I click a row in the parent, the child grid will refresh with data associated to the row. I do this by getting the parent to call a "refresh" method in the child from the parent's "selectedIndexChanged" event. The "refresh" method gets data from the database. Then it calls a "rebind" on the grid, which calls the needDatasource method, then the ItemDataBound method. In the ItemDataBound, based on rules, I decide to show or hide an edit icon. When I select rows in the parent, this code fires, and tracing thru, it's setting the correct "true" value to the visible property of my edit icon, however when the page is shown, the icon is not there. Any reason why this is getting lost?
My ugly workaround is to add another method after the "rebind" that basically is the same as the ItemDataBound code which finds the grid, finds my rows, and shows/hides the icons.
public void RefreshChild)
{
LoadChildGridDataFromDataBase();
ChildGrid.Rebind();
//ugly
DoTheItemDataBoundStuffAgain()
}
6 Answers, 1 is accepted
If you could share a little more about the scenario or the methods you have mentioned, I'd be able to see and understand where the problem comes from and advise you accordingly. If would be helpful even if you could share the markup and code behind.
I look forward to hearing from you.
Kind regards,
Attila Antal
Progress Telerik


Parent_Grid_SelectedIndexChanged
calls Child_Control.Refresh();
public
void
Refresh()
{
LoadDataFromDataBase();
//force a call to Child_Grid_NeedDataSource from Rebind().
//If it is not set to NULL, it wont call it.
Child_Grid.DataSource =
null
;
Child_Grid.Rebind();
/*Even though the Rebind() call above will trigger _ItemDataBound and assign the correct values
to editButton.Visible, it seems they get lost for some reason. The call below to Initialize will restore
it but we shouldnt need to do this.
*/
Initialize();
}
Rebind() calls the needDatasource method:
Child_Grid.DataSource = Data_from_the_LoadDataFromDataBase_method;
then the ItemDataBound method:
protected
void
Child_Grid_ItemDataBound(
object
sender, GridItemEventArgs e)
{
if
(e.Item
is
GridDataItem)
//hide the edit/delete images in the rows
{
GridDataItem item = (GridDataItem)e.Item;
ImageButton editButton = (ImageButton)item[
"editButton"
].Controls[0];
ImageButton deleteButton = (ImageButton)item[
"deleteButton"
].Controls[0];
editButton.Visible =
true
;
deleteButton.Visible =
true
;
}
}
protected
void
Initialize()
{
//find the AlternateLabour Grid
RadGrid grid = (RadGrid)
this
.FindControl(
"Child_Grid"
);
//hide the edit/delete images in the rows
grid.MasterTableView.GetColumn(
"editButton"
).Visible =
true
;
grid.MasterTableView.GetColumn(
"deleteButton"
).Visible =
true
;
}
Thank you for the additional information.
Sometimes, it is would could be really helpful to share additional details on the scenario such as how the grid is created (declaratively, programmatically), which hierarchical structure is used? Is it Master/Detail tables or using Template hierarchy with NestedViewTemplate? These are details that are crucial and each can behave differently.
Based on the code snippets you have provided now, I assume that Child_Grid is in a NestedViewTemplate, is that correct? Can you tell me more about the deleteButton and editButton, are those UniqueNames of different columns? Are you using the built-in Edit/Delete columns or you're creating them using GridTemplateColumn?
Accessing controls in a Template column is different then in built-in columns. For more information, check out the Accessing Cells and Rows article.
I have attached a basic sample with no hierarchy but the grid has Template columns for Edit/Delete and some of the buttons are getting hidden based on condition of each row. I would like you to modify this sample to reflect the scenario from you side and send it back to us for further investigation.
Kind regards,
Attila Antal
Progress Telerik

Two separate radgrids.
When selectedIndexChanged occurs on the First, I call a refresh method on the second Radgrid.
The edit button is a GridEditCommandColumn, delete is a GridButtonColumn.
Accessing them isn't an issue. We do this logic in other areas of our app. Just seems for this, the changes in ItemDataBound do not stay so I have to call another method to do the same logic.
Have you had the chance to check out the sample project I have attached in my previous post? Can you confirm whether it works for you?
It would be very helpful If you could modify that sample project to produce the error and send it back to us for further investigation.
Kind regards,
Attila Antal
Progress Telerik