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

Hierarchy grid - hide cells when expanded

2 Answers 55 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Kamen
Top achievements
Rank 1
Kamen asked on 19 May 2011, 06:48 PM
Is there a way to define a hierarchy grid, but when I expand a particular row (too see its nested item) to hide all the cells in that row?

Something like here: http://demos.telerik.com/aspnet-ajax/grid/examples/hierarchy/declarativerelations/defaultcs.aspx
But when the first row is expanded and I see the inner grid, I want to have the cells that contain: "ALFKI", "Maria Anders" and "Alfreds Futterkiste" hidden. And when I collapse the first row to have that cells displayed.

If there is no way to do that feel free to offer another solution.

Thanks,
Kamen

2 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 20 May 2011, 10:30 AM
Hello Kamen,

Attach ItemCommand event to your RadGrid and then set the visibility of parent table in PreRender event by checking the global variables. Here is the sample code that I tried. Hope this helps you.

C#:
public partial class _Default : System.Web.UI.Page
{
    int index = 0,flag=0;//global variables
protected void RadGrid2_ItemCommand(object sender, GridCommandEventArgs e)
 {
     if (e.CommandName == RadGrid.ExpandCollapseCommandName)//checking for CommandName
        {
          if (!e.Item.Expanded)
            {
                index = e.Item.ItemIndex;
                flag = 1;
            }
            else
            {
                flag=0;
                index=e.Item.ItemIndex;
            }
   }
 }
protected void RadGrid2_PreRender(object sender, EventArgs e)
 {
      if ((index >= 0) && (flag == 1))
        {
    GridDataItem item=(GridDataItem)RadGrid2.Items[index];
     TableCell cell = item["ContactName"];
     cell.Visible = false;//hidind parentItem
 }
        else
        {
            GridDataItem item = (GridDataItem)RadGrid2.Items[index];
            TableCell cell = item["ContactName"];
            cell.Visible = true;
        }
 }
}

Thanks,
Princy.
0
Kamen
Top achievements
Rank 1
answered on 20 May 2011, 02:48 PM
Thanks very much for the quick and helpful response!
Tags
Grid
Asked by
Kamen
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Kamen
Top achievements
Rank 1
Share this question
or