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

[Solved] Dynamically controlling RadGrid Hierarchy

1 Answer 65 Views
Grid
This is a migrated thread and some comments may be shown as answers.
DC
Top achievements
Rank 1
DC asked on 16 Dec 2009, 10:20 AM
Hi,
I have a Hierarchial RadGrid. My page is "role driven" which means, I need to show hierarchy for one role and not for others. How can I control it from codebehind.

1 Answer, 1 is accepted

Sort by
0
Mira
Telerik team
answered on 18 Dec 2009, 01:14 PM
Hello,

I suggest that you hide the detail tables of the RadGrid depending on the role of the user in the following way:
protected void RadGrid1_PreRender(object sender, EventArgs e)
{
    if (!User.IsInRole("admin"))
    {
        HideDetailTablesRecursive(RadGrid1.MasterTableView);
    }
      
}
public void HideDetailTablesRecursive(GridTableView tableView)
{
    GridItem[] nestedViewItems = tableView.GetItems(GridItemType.NestedView);
    foreach (GridNestedViewItem nestedViewItem in nestedViewItems)
    {
        foreach (GridTableView nestedView in nestedViewItem.NestedTableViews)
        {
            if (nestedView.Items.Count == 0)
            {
                TableCell cell = nestedView.ParentItem["ExpandColumn"];
                cell.Controls[0].Visible = false;
                nestedViewItem.Visible = false;
            }
            if (nestedView.HasDetailTables)
            {
                HideDetailTablesRecursive(nestedView);
            }
        }
    }
}
I am also attaching a sample project showing how the hiding of the detail tables works.

I hope this helps.

All the best,
Mira
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
Grid
Asked by
DC
Top achievements
Rank 1
Answers by
Mira
Telerik team
Share this question
or