Self Referencing hierarchy grid : Expand All

2 posts, 0 answers
  1. Bill
    Bill avatar
    1 posts
    Member since:
    Mar 2012

    Posted 28 Mar 2012 Link to this post


    I have a self-referencing grid.  I'm declaring it and configuring it all in the aspx declaration and binding it via the "rebind"-"needs-data" approach.   It works fantastic.

    The grid is initialized with a large data set (using the HierarchyLoadMode="ServerOnDemand") mode, and I have some PreRender code that expands the first 2 levels of the hierarchy.

    Now the user can filter data, we are not using the grids filter but re-querying the database and returning a new dataset and rebinding to the grid.  If that dataset contains less than 20 records, the user wants all the nodes expanded by default, otherwise only the first 2.

    I've tried several approaches: 
    1.) Expanding in pre-render.  Doesn't work, only 2 sub-layers have data.
    2.) changing HierarchyLoadMode to "ServerBind" and expanding in Pre-Render using a recursive expand function (code listed below)   Seems to work until the 4th sub-level, after the 4th sublevel the item.ChildItem.NestedTableViews.count is 0, even though I know there are 6 levels in the data set.

    My next step is to try it with HierarchyLoadMode = "client" and my last ditch effort to dynmically build the grid for every request.  any guidence would be appreciated.

    protected void RadGrid1_PreRender(object sender, EventArgs e)

                if (ExpandAll)


            private void RadGridExpandHierarchy(GridDataItemCollection items)
                foreach (GridDataItem item in items)
                    if (item.GetDataKeyValue("IsPolicyRow").ToString()=="0" && item.ChildItem != null && item.ChildItem.NestedTableViews != null && item.ChildItem.NestedTableViews.Count() > 0)
                        GridTableView childtableView = (GridTableView)item.ChildItem.NestedTableViews[0];
                    if (item.CanExpand && item.GetDataKeyValue("IsPolicyRow").ToString() == "0")
                        item.Expanded = true;


  2. Tsvetina
    Tsvetina avatar
    2087 posts

    Posted 02 Apr 2012 Link to this post

    Hi Bill,

    I would advise you to use the RadTreeList control which is designed for displaying self-referencing data. With it, the code for expanding the items as required would look similar to this:
    protected void RadTreeList1_PreRender(object sender, EventArgs e)
        if (!IsPostBack)
            if (RadTreeList1.Items.Count < 2)
                RadTreeList1.Items[0].Expanded = true;
                RadTreeList1.Items[1].Expanded = true;

    All the best,
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Back to Top