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

Self-referencing Hierarchy Issue

8 Answers 203 Views
Grid
This is a migrated thread and some comments may be shown as answers.
digitall
Top achievements
Rank 1
digitall asked on 09 Jul 2008, 03:41 PM
I am trying to use the self-referencing hierarchy functionality of the grid but can't seem to get it to work properly. I even tried copying the code directly from the tutorial specified here verbatim into a new page and I continually get the same error: "No property or field 'ParentID' exists in type 'DataRowView'."

My application has the following grid definition:

    <telerik:RadGrid ID="RadGrid2" runat="server" Skin="" Width"97%" OnNeedDataSource"RadGrid2_NeedDataSource" GridLines="None" ShowHeader="False">  
        <MasterTableView HierarchyDefaultExpanded="True" HierarchyLoadMode="Client" DataKeyNames"NETT_ID,NETT_IS_ID" Width="100%" AutoGenerateColumns="False">  
        <SelfHierarchySettings ParentKeyName="NETT_IS_ID" KeyName="NETT_ID" MaximumDepth="0" /> 
        <Columns> 
            <telerik:GridBoundColumn HeaderText="NETT_ID" DataField="NETT_ID" /> 
            <telerik:GridBoundColumn HeaderText="NETT_IS_ID" DataField="NETT_IS_ID" /> 
            <telerik:GridBoundColumn HeaderText="Intermediate Stock" DataField="NETT_PRODUCT" /> 
        </Columns> 
    </MasterTableView> 
</telerik:RadGrid>  

When I run it against my data source, the grid binds great and even has the hierarchy as I would expect with one exception - ALL records are displayed as if they are parent records in addition to the one record that should be a parent record (which has all records again as children). I need to get rid of all the "top elements" with the exception of the one that is really supposed to be the parent. In the future multiple top-level parent elements will exist (all with a NETT_IS_ID value of 0), but currently only one does.

I tried using FilterExpressions, but even when I use the sample code provided from the Knowledge Base, it doesn't run. It just tells me the column NETT_IS_ID doesn't exist in the dataview, even though I can bind to it directly and it does in fact exist.

In case it helps, here is my code-behind:
        protected void Page_Load(object sender, EventArgs e)  
        {  
            site mstr = (site)this.Master;  
            mstr.PageHeader = "Intermediate Stock";  
 
            this.PreRenderComplete += new EventHandler(Page_PreRenderComplete);  
            //this.BindData();  
        }  
 
        DataTable BindData()  
        {  
 
            DataSet ds = new DataSet();  
 
            using (OracleConnection conn = new OracleConnection(ConfigurationManager.ConnectionStrings["IntermediateStock"].ConnectionString))  
            {  
 
                using (OracleCommand cm = new OracleCommand())  
                {  
 
                    cm.Connection = conn;  
                    cm.CommandText = "IS_NETT.GET_PRODUCT_TREE";  
                    cm.CommandType = CommandType.StoredProcedure;  
 
                    OracleParameter param = new OracleParameter();  
                    param.Direction = ParameterDirection.Output;  
                    param.ParameterName = "IO_CURSOR";  
                    param.OracleType = OracleType.Cursor;  
 
                    cm.Parameters.Add(param);  
 
                    using (OracleDataAdapter da = new OracleDataAdapter(cm))  
                    {  
                        //da.TableMappings.Add("Table", "ISResults");  
                        da.Fill(ds, "Table");  
                    }  
 
                }  
 
            }  
 
            DataColumn[] keys = new DataColumn[1];  
            keys[0] = ds.Tables[0].Columns["NETT_ID"];  
 
            ds.Tables[0].PrimaryKey = keys;  
 
            return ds.Tables[0];  
 
        }  
 
        protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)  
        {  
            this.RadGrid1.DataSource = this.BindData();  
        }  
 
        protected void RadGrid2_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)  
        {  
            this.RadGrid2.DataSource = this.BindData();  
        }  
 
        public void Page_PreRenderComplete(object sender, EventArgs e)  
        {  
            HideExpandColumnRecursive(RadGrid1.MasterTableView);  
            HideExpandColumnRecursive(RadGrid2.MasterTableView);  
        }  
        public void HideExpandColumnRecursive(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)  
                    {  
                        HideExpandColumnRecursive(nestedView);  
                    }  
                }  
            }  
        }   
    }  
}  
 

Any suggestions?

8 Answers, 1 is accepted

Sort by
0
Veli
Telerik team
answered on 10 Jul 2008, 12:28 PM
Hello Scott,

Please find attached a sample project derived from the help article, demonstrating the self-hierarchy settings. Please see how it relates to your case.

Sincerely yours,
Veli
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
digitall
Top achievements
Rank 1
answered on 10 Jul 2008, 01:14 PM
Veli,

Thanks for the project. Using the code from it I found I could just hide any columns with a NETT_IS_ID value that wasn't 0 which worked perfectly. That option didn't even cross my mind for some reason.

Thanks again for the quick and always great support!
0
Joyce
Top achievements
Rank 1
answered on 19 Aug 2008, 08:37 PM
Hello,

I too am wanting to have a self-referencing hierarchy but I want to have the parent columns to be different than the Child columns. 

None of the examples even discuss this option for binding to a single datasource and showing different column details for the hierarchical detail tables.

Am I missing something?

0
Yavor
Telerik team
answered on 20 Aug 2008, 05:21 AM
Hello,

You can basically hide different items in the control, to achieve a similar functionality. Or, you can consider using a standard hierarchy, which has this by default.

Regards,
Yavor
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Yuvika
Top achievements
Rank 1
answered on 16 Jun 2010, 08:07 AM
Hi,

I am using self hierachical settings in details section of grid as shown in the code below:
 <telerik:RadGrid GroupingEnabled="false" Skin="Web20" ID="grdDomain" runat="server" 
            AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False" EnableEmbeddedSkins="false" 
            Width="100%" OnNeedDataSource="grdDomain_NeedDataSource" OnDetailTableDataBind="grdDomain_DetailTableDataBind" 
            PageSize="10" GridLines="None">  
            <MasterTableView AllowMultiColumnSorting="True" AllowPaging="True" AutoGenerateColumns="false" 
                HierarchyLoadMode="ServerOnDemand" AllowSorting="true" runat="server" DataKeyNames="DomainID" 
                ExpandCollapseColumn-Display="true" ExpandCollapseColumn-ItemStyle-Width="5%" 
                ExpandCollapseColumn-FilterControlWidth="5%" ExpandCollapseColumn-HeaderStyle-Width="3%">  
                <DetailTables> 
                    <telerik:GridTableView ShowHeader="false" Name="EmailSenderInfo" Width="100%" DataKeyNames="EmailAddress">  
                        <ParentTableRelation> 
                            <telerik:GridRelationFields DetailKeyField="DomainID" MasterKeyField="DomainID" /> 
                        </ParentTableRelation> 
                        <Columns> 
                            <telerik:GridTemplateColumn ItemStyle-Width="30px" UniqueName="Checkbox" HeaderStyle-Width="30px">  
                                <ItemTemplate> 
                                    <asp:CheckBox runat="server" ID="chkSelectRow" /> 
                                </ItemTemplate> 
                            </telerik:GridTemplateColumn> 
                            <telerik:GridBoundColumn ItemStyle-Width="100%" HeaderStyle-Width="100%" DataField="EmailAddress" 
                                HeaderText="EmailAddress" SortExpression="EmailAddress">  
                            </telerik:GridBoundColumn> 
                        </Columns> 
                        <DetailTables> 
                            <telerik:GridTableView DataKeyNames="FileID,FileParentID" NoMasterRecordsText="No Master Records" 
                                NoDetailRecordsText="No Detail Records" Width="100%" Height="100%" Name="FileDetails">  
                                <SelfHierarchySettings KeyName="FileID" ParentKeyName="FileParentID" /> 
                                <Columns> 
                                    <telerik:GridTemplateColumn UniqueName="Checkbox" HeaderStyle-Width="30px">  
                                        <HeaderTemplate> 
                                            <asp:CheckBox runat="server" ID="chkHeader" /> 
                                        </HeaderTemplate> 
                                        <ItemTemplate> 
                                            <asp:CheckBox runat="server" ID="chkSelectRow" /> 
                                        </ItemTemplate> 
                                    </telerik:GridTemplateColumn> 
                                    <telerik:GridTemplateColumn ItemStyle-Wrap="false" SortExpression="Custodian" UniqueName="Custodian" 
                                        HeaderStyle-HorizontalAlign="Left" ItemStyle-HorizontalAlign="Left" HeaderText="Custodian">  
                                        <ItemTemplate> 
                                            <asp:Label ID="lblCustodian" runat="server" Text='<%#Eval("Custodian")%>'></asp:Label> 
                                        </ItemTemplate> 
                                    </telerik:GridTemplateColumn> 
                                    <telerik:GridTemplateColumn ItemStyle-Wrap="false" UniqueName="OurName" HeaderStyle-HorizontalAlign="Left" 
                                        ItemStyle-HorizontalAlign="Left" HeaderText="Our Name">  
                                        <ItemTemplate> 
                                            <asp:Label ID="lblOurName" runat="server" Text='<%#Eval("OurName")%>'></asp:Label> 
                                        </ItemTemplate> 
                                    </telerik:GridTemplateColumn> 
                                    <telerik:GridTemplateColumn ItemStyle-Wrap="true" SortExpression="Size" UniqueName="Size" 
                                        HeaderStyle-HorizontalAlign="Left" HeaderText="Size (Bytes)" ItemStyle-HorizontalAlign="Right" 
                                        HeaderStyle-Width="80px">  
                                        <ItemTemplate> 
                                            <asp:Label ID="lblSize" runat="server" Text='<%#Eval("Size")%>'></asp:Label> 
                                        </ItemTemplate> 
                                    </telerik:GridTemplateColumn> 
                                    <telerik:GridBoundColumn DataField="SystemName" HeaderText="SystemName" SortExpression="SystemName">  
                                    </telerik:GridBoundColumn> 
                                    <telerik:GridBoundColumn DataField="ParentID" HeaderText="ParentID" SortExpression="ParentID">  
                                    </telerik:GridBoundColumn> 
                                </Columns> 
                            </telerik:GridTableView> 
                        </DetailTables> 
                        <NoRecordsTemplate> 
                            No Record(s) found...</NoRecordsTemplate> 
                    </telerik:GridTableView> 
                </DetailTables> 
                <Columns> 
                    <telerik:GridBoundColumn DataField="DomainName" HeaderText="Domain Name" SortExpression="DomainName">  
                    </telerik:GridBoundColumn> 
                </Columns> 
            </MasterTableView> 
            <ClientSettings AllowExpandCollapse="true">  
                <ClientEvents OnColumnContextMenu="ColumnContextMenu" /> 
            </ClientSettings> 
        </telerik:RadGrid> 

The binding is done as below:
protected void grdDomain_DetailTableDataBind(object sender, GridDetailTableDataBindEventArgs e)  
        {  
            if (e.DetailTableView.Name == "FileDetails")  
            {  
                GridDataItem item = (GridDataItem)e.DetailTableView.ParentItem;  
                string emailAddress = item.GetDataKeyValue("EmailAddress").ToString();  
                e.DetailTableView.DataSource = BatchDB.GetFileDetailsForSender(Common.Common.CurrentSearchCriteria.ProjectName, emailAddress);  
                if (Assembly.GetAssembly(typeof(ScriptManager)).FullName.IndexOf("3.5") != -1)  
                {  
                    e.DetailTableView.FilterExpression = @"it[""FileParentID""] = Convert.DBNull";  
                }  
                else  
                {  
                    e.DetailTableView.FilterExpression = "FileParentID IS NULL";  
                }  
            }  
            else if (e.DetailTableView.Name == "EmailSenderInfo")  
            {  
                GridDataItem item = (GridDataItem)e.DetailTableView.ParentItem;  
                string DomainID = item.GetDataKeyValue("DomainID").ToString();  
                e.DetailTableView.DataSource = BatchDB.GetSenderDetailForDomain(Common.Common.CurrentSearchCriteria.ProjectName, Convert.ToInt32(DomainID));  
            }  
        }  
                protected void grdDomain_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)  
        {  
            grdDomain.DataSource = BatchDB.GetAllDomainsInProject(Common.Common.CurrentSearchCriteria.ProjectName);  
        } 
But the problem is that the innermost detail table is not being self refernced. i just get the root data, the data in self referencing is not being populated. What an be the issue?. Or Am I missing some property.
 
Please review and reply.
Thanks
Yuvika
0
Yavor
Telerik team
answered on 16 Jun 2010, 12:17 PM
Hi Yuvika,

Can you please confirm that the data passed to the grid control is valid and conforms to the self-referencing data structure? If the problem persists, you can also open a formal support ticket, and send us the problematic code, for additional review and testing.

All the best,
Yavor
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.
0
Yuvika
Top achievements
Rank 1
answered on 16 Jun 2010, 12:30 PM
Hi,

Yes the data is self referenced. Please see teh image attached to conform that.
I am using such data on other grid which is self referenced only. But in my current situaton the grid has details able and relation etween them , and at third level I want data to be self referenced. which is not working in my case. Please see the code above for grid structure and deatils.

Thanks,
Yuvika
0
Yavor
Telerik team
answered on 17 Jun 2010, 11:09 AM
Hi Yuvika,

Upon reviewing the setup again, I noticed the settings which you have included.
Please, keep in mind, that mixing standard hierarchy, and self-referencing hierarchy is not supported at present. You can have either a standard hierarchy, or a selfreferencing one. Another option is to use a nested view template.
I hope one of these options is suitable for you.

Greetings,
Yavor
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
Tags
Grid
Asked by
digitall
Top achievements
Rank 1
Answers by
Veli
Telerik team
digitall
Top achievements
Rank 1
Joyce
Top achievements
Rank 1
Yavor
Telerik team
Yuvika
Top achievements
Rank 1
Share this question
or