by Tom Hundley
19. May 2010 08:23
Often times when using nested grids, you may desire to hide the expand/collapse button if there are no child items. This is very easy to do, although it’s not as intuitive as you might think. This example will show you how to accomplish this task using a Telerik RadGrid for ASP.Net Ajax.
1. First, subscribe to the PreRender event of the Grid control.
2. Loop through the GridNestedViewItems.
3. Apply your visibility logic.
protected void rgParts_PreRender(object sender, EventArgs e)
{
GridItem[] nestedViewItems = rgParts.MasterTableView.GetItems(GridItemType.NestedView);
foreach (GridNestedViewItem nestedViewItem in nestedViewItems)
{
foreach (GridTableView nestedView in nestedViewItem.NestedTableViews)
{
if (((Foo)nestedView.ParentItem.DataItem).Prop1 == "DontShowExpandColmn")
{
TableCell cell = nestedView.ParentItem["ExpandColumn"];
cell.Controls[0].Visible = false;
nestedViewItem.Visible = false;
}
}
}
}
Tom Hundley
Elegant Software Solutions, LLC