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

Self-Referencing Hierarchy Guidance

1 Answer 61 Views
This is a migrated thread and some comments may be shown as answers.
Clint Leonard
Top achievements
Rank 1
Clint Leonard asked on 30 Aug 2010, 05:01 PM

I need guidance on how best to create a self-referencing hierarchy grid where the datasource is delegate that returns an IList<>.

Once my mastertables rows are retrieved, I am able to expand the rows, which causes the NeedDatasource event to be fired where I attempt to grab that rows dependent objects and set the datasource to them, but the detail view is always empty.

I am guessing at this point I am going about this the wrong way and am hoping you can point me in the right direction.


Here is the grid:

<telerik:RadGrid ID="rgDependentObjects" runat="server" AllowCustomPaging="True" 
        AllowMultiRowSelection="True" AllowPaging="True" AutoGenerateColumns="False"
        GridLines="None" OnItemCreated="rgDependentObjects_ItemCreated" OnDetailTableDataBind="rgDependentObjects_DetailTableDataBind">
        <PagerStyle BackColor="White" Mode="Advanced" ShowPagerText="false" Position="Bottom" />
        <MasterTableView AllowCustomSorting="True" datakeynames="ParentObject.ID,DependentObject.ID" EditMode="InPlace"
                         HierarchyDefaultExpanded="false" HierarchyLoadMode="ServerOnDemand">
            <SelfHierarchySettings ParentKeyName="ParentObject.ID" KeyName="DependentObject.ID" />
                <telerik:GridClientSelectColumn HeaderText="Delete">
                    <ItemStyle Width="6px" />
                <telerik:GridHyperLinkColumn DataNavigateUrlFields="ParentObject.ID" 
                <telerik:GridBoundColumn DataField="ParentObjectType" DataType="System.String" SortExpression="ObjectType" HeaderText="Object Type" />                                    
        <ClientSettings AllowExpandCollapse="true">
            <Selecting AllowRowSelect="True" />

The Datasource for the mastyer table in rgDependentObject is:
private IList<TruComply.DomainObjects.ScopeObjectDependency> GetDependentObjectsForAsset(out int totalRecords, TruComply.DomainObjects.Interfaces.ICriteria criteria)
    //get the collection from the manager and return
    //return scopeManager.GetDependentObjectsForAsset(currentAssetID, out totalRecords, criteria);            
    criteria = CriteriaBuilder.CreateCriteria(ExpressionBuilder.Is("DependentObject.ID", currentAssetID));
    criteria.And(ExpressionBuilder.IsNot("ParentObjectType", "AssetGroup"));
    return scopeManager.GetScopeObjectDependencies(out totalRecords, criteria);

The NeedDatasource event:
protected void rgDependentObjects_DetailTableDataBind(object source, Telerik.Web.UI.GridDetailTableDataBindEventArgs e)
    //get the detail vie's parent item
    GridDataItem dataItem = (GridDataItem)e.DetailTableView.ParentItem;
    if (e.DetailTableView.Name == "")
        int totalRecords = 0;
        ICriteria criteria = CriteriaBuilder.CreateCriteria(ExpressionBuilder.Is("DependentObject.ID", dataItem.GetDataKeyValue("ParentObject.ID").ToString()));
        criteria.And(ExpressionBuilder.IsNot("ParentObjectType", "AssetGroup"));
        IList<ScopeObjectDependency> scopeObjectDependencies = scopeManager.GetScopeObjectDependencies(out totalRecords, criteria);
        e.DetailTableView.VirtualItemCount = scopeObjectDependencies.Count();
        e.DetailTableView.DataSource = scopeObjectDependencies;

1 Answer, 1 is accepted

Sort by
Iana Tsolova
Telerik team
answered on 02 Sep 2010, 12:16 PM
Hello Clint,

With the self-referencing grid you need to handle the NeedDataSource event only. And there assign a datasource for the grid which contains all records, either these that will be shown in the master table view and these that will the displayed in the nested levels.

Best wishes,
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Asked by
Clint Leonard
Top achievements
Rank 1
Answers by
Iana Tsolova
Telerik team
Share this question