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

Self-Referencing Hierarchy Problem

4 Answers 57 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Kyle
Top achievements
Rank 1
Kyle asked on 12 Oct 2012, 08:36 PM
I'm pretty sure I'm just doing something incorrectly, but here we go.

I'm trying to get a self-referencing hierarchy grid where the first grid and it's hierarchy is linked by ID and DirectParent and its second hierarchy is linked by ChildID and DirectParent so you'd have:
Ben
Ralph
Ralph's Age
Ralph's Eye Color
Betty
Ruth
Ruth's Height
Ruth's Shoe Size
David
David's Age
Sam
Beth
Beth's Blood Type

If the lines in the ASPX below are uncommented then the structure is there, but on the second level, it's like the entire data source just comes out on that line. If you leave in the commenting lines in then you can see what I want, but only for the first and second levels, but not the third. What am I doing wrong here? I also have this "MyRadGrid.MasterTableView.FilterExpression = "DirectParent IS NULL";" in the page load method. I've tried setting a filter on the detail tables, but nothing. Any suggestions are appreciated.

I'm working with a DataTable with Data that resembles this form:
Columns: ID, ChildID, Name, Value, DirectParent
myData.Rows.Add(0, 0, "Ben", "has no kids", DBNull.Value);
 
myData.Rows.Add(1, 0, "Ralph", "has no kids", DBNull.Value);
myData.Rows.Add(2, 0, "Betty", "is a mother", DBNull.Value);
myData.Rows.Add(3, 0, "David", "is a father", DBNull.Value);
 
myData.Rows.Add(0, 0, "Ralph's Age", "33", 1);
myData.Rows.Add(0, 0, "Ralph's Eye Color", "Red", 1);
myData.Rows.Add(0, 0, "David's Age", "77", 3);
 
myData.Rows.Add(0, 4, "Sam", "is David's son", 3);
myData.Rows.Add(0, 5, "Beth", "is David's daughter", 3);
myData.Rows.Add(0, 6, "Ruth", "is Betty's daughter", 2);
 
myData.Rows.Add(0, 0, "Beth's Blood Type", "O+", 5);
myData.Rows.Add(0, 0, "Ruth's Height", "82 inches", 6);
myData.Rows.Add(0, 0, "Ruth's Shoe Size", "10", 6);


And my ASPX is as follows

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
 
<%@ Register Assembly="RadGrid.Net2" Namespace="Telerik.WebControls" TagPrefix="rad" %>
<!DOCTYPE html>
 
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
        <div>
            <%-- Old, but working
            <rad:RadGrid runat="server" ID="MyRadGrid" OnNeedDataSource="MyRadGrid_NeedDataSource" MasterTableView-HierarchyLoadMode="Client" OnPreRender="MyRadGrid_PreRender">
                <MasterTableView HierarchyDefaultExpanded="true" HierarchyLoadMode="Client" DataKeyNames="TheParent, GUID" FilterExpression="TheParent = 0" ShowHeadersWhenNoRecords="false">
                    <SelfHierarchySettings ParentKeyName="TheParent" KeyName="GUID" MaximumDepth="3" />
                </MasterTableView>
                <ClientSettings AllowExpandCollapse="true"></ClientSettings>
            </rad:RadGrid>
            --%>
            <rad:RadGrid runat="server" ID="MyRadGrid" OnNeedDataSource="MyRadGrid_NeedDataSource" MasterTableView-HierarchyLoadMode="Client" OnPreRender="MyRadGrid_PreRender">
                <MasterTableView HierarchyDefaultExpanded="true" HierarchyLoadMode="Client" DataKeyNames="DirectParent, ID" ShowHeadersWhenNoRecords="false">
                    <SelfHierarchySettings ParentKeyName="DirectParent" KeyName="ID" MaximumDepth="3" />
                    <%--
                    <DetailTables>
                        <rad:GridTableView HierarchyDefaultExpanded="true" HierarchyLoadMode="Client" DataKeyNames="DirectParent, ChildID" ShowHeadersWhenNoRecords="false">
                            <SelfHierarchySettings ParentKeyName="DirectParent" KeyName="ChildID" MaximumDepth="1" />
                        </rad:GridTableView>
                    </DetailTables>
                    --%>   
                </MasterTableView>
                <ClientSettings AllowExpandCollapse="true"></ClientSettings>
            </rad:RadGrid>
        </div>
    </form>
</body>
</html>

Also, please excuse the structure of this DataTable. It isn't representative of any crazy database where IDs aren't unique.

4 Answers, 1 is accepted

Sort by
0
Kyle
Top achievements
Rank 1
answered on 16 Oct 2012, 03:23 PM
4 day bump
0
Andrey
Telerik team
answered on 17 Oct 2012, 11:18 AM
Hi,

Could you share what columns are included in the DataTable? The name and the order are important for the self-hierarchy. Sample project that replicates the issue, could reduce the needed time for resolving the issue.

Additionally, you could check this online demo application for a sample project that uses Self-referenced hierarchy.

You could consider using the TreeList control, it is designed to be used in such scenarios.
Greetings,
Andrey
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.
0
Kyle
Top achievements
Rank 1
answered on 17 Oct 2012, 07:21 PM
A TreeList? That sounds interesting. I think I'll go that route then, but how would I create the connections for different levels of the hierarchy based on different IDs and ParentIDs? Like before I said I would like the root level to have everything with no parent, then the second level is linked to the first by TheParent<--> ID then the next level is linked by TheParent<--> QID I don't really see that in the demo for self-referencing in such a way. Is this a viable thing to do or would I probably need to figure out a better way to structure my DataTable?

Also, you requested this:
DataTable myData = new DataTable();
myData.Columns.Add("GUID", typeof(int));
myData.Columns.Add("QID", typeof(int));
myData.Columns.Add("Level", typeof(int));
myData.Columns.Add("Description", typeof(string));
myData.Columns.Add("TheParent", typeof(int));

I got the TreeList working easily enough using other sample data that only uses one ID column. Seems nice, but I'll have to add indenting to each sub-row later.

Thanks a lot.

------------------------
Scratch all of that actually. We decided we will use nested RadGrids with expand/collapse buttons to achieve something similar, but thanks for getting back to me. I'll open a separate thread if I run into problems with anything though!
0
Andrey
Telerik team
answered on 22 Oct 2012, 10:44 AM
Hello,

The structure you want to achieve is not a self-referencing hierarchy, it is a classic hierarchy structure as the one shown in this online demo application.

The self-referencing hierarchy as its name suggest is created based on two fields and the values of these fields. Based on the values in these fields the levels are calculated, for the root level is taken the null or 0 value and under it the other levels are created.

You could check this online demo of RadTreeList for a demonstration of self-referenced data and this help topic which sheds more light on the self-referencing data in general.


Regards,
Andrey
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.
Tags
Grid
Asked by
Kyle
Top achievements
Rank 1
Answers by
Kyle
Top achievements
Rank 1
Andrey
Telerik team
Share this question
or