Self-referencing Hierarchy Issue

9 posts, 0 answers
  1. digitall
    digitall avatar
    169 posts
    Member since:
    Jun 2006

    Posted 09 Jul 2008 Link to this post

    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:

    1     <telerik:RadGrid ID="RadGrid2" runat="server" Skin="" Width"97%" OnNeedDataSource"RadGrid2_NeedDataSource" GridLines="None" ShowHeader="False">  
    2         <MasterTableView HierarchyDefaultExpanded="True" HierarchyLoadMode="Client" DataKeyNames"NETT_ID,NETT_IS_ID" Width="100%" AutoGenerateColumns="False">  
    3         <SelfHierarchySettings ParentKeyName="NETT_IS_ID" KeyName="NETT_ID" MaximumDepth="0" /> 
    4         <Columns> 
    5             <telerik:GridBoundColumn HeaderText="NETT_ID" DataField="NETT_ID" /> 
    6             <telerik:GridBoundColumn HeaderText="NETT_IS_ID" DataField="NETT_IS_ID" /> 
    7             <telerik:GridBoundColumn HeaderText="Intermediate Stock" DataField="NETT_PRODUCT" /> 
    8         </Columns> 
    9     </MasterTableView> 
    10 </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:
    1         protected void Page_Load(object sender, EventArgs e)  
    2         {  
    3             site mstr = (site)this.Master;  
    4             mstr.PageHeader = "Intermediate Stock";  
    5  
    6             this.PreRenderComplete += new EventHandler(Page_PreRenderComplete);  
    7             //this.BindData();  
    8         }  
    9  
    10         DataTable BindData()  
    11         {  
    12  
    13             DataSet ds = new DataSet();  
    14  
    15             using (OracleConnection conn = new OracleConnection(ConfigurationManager.ConnectionStrings["IntermediateStock"].ConnectionString))  
    16             {  
    17  
    18                 using (OracleCommand cm = new OracleCommand())  
    19                 {  
    20  
    21                     cm.Connection = conn;  
    22                     cm.CommandText = "IS_NETT.GET_PRODUCT_TREE";  
    23                     cm.CommandType = CommandType.StoredProcedure;  
    24  
    25                     OracleParameter param = new OracleParameter();  
    26                     param.Direction = ParameterDirection.Output;  
    27                     param.ParameterName = "IO_CURSOR";  
    28                     param.OracleType = OracleType.Cursor;  
    29  
    30                     cm.Parameters.Add(param);  
    31  
    32                     using (OracleDataAdapter da = new OracleDataAdapter(cm))  
    33                     {  
    34                         //da.TableMappings.Add("Table", "ISResults");  
    35                         da.Fill(ds, "Table");  
    36                     }  
    37  
    38                 }  
    39  
    40             }  
    41  
    42             DataColumn[] keys = new DataColumn[1];  
    43             keys[0] = ds.Tables[0].Columns["NETT_ID"];  
    44  
    45             ds.Tables[0].PrimaryKey = keys;  
    46  
    47             return ds.Tables[0];  
    48  
    49         }  
    50  
    51         protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)  
    52         {  
    53             this.RadGrid1.DataSource = this.BindData();  
    54         }  
    55  
    56         protected void RadGrid2_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)  
    57         {  
    58             this.RadGrid2.DataSource = this.BindData();  
    59         }  
    60  
    61         public void Page_PreRenderComplete(object sender, EventArgs e)  
    62         {  
    63             HideExpandColumnRecursive(RadGrid1.MasterTableView);  
    64             HideExpandColumnRecursive(RadGrid2.MasterTableView);  
    65         }  
    66         public void HideExpandColumnRecursive(GridTableView tableView)  
    67         {  
    68             GridItem[] nestedViewItems = tableView.GetItems(GridItemType.NestedView);  
    69             foreach (GridNestedViewItem nestedViewItem in nestedViewItems)  
    70             {  
    71                 foreach (GridTableView nestedView in nestedViewItem.NestedTableViews)  
    72                 {  
    73                     if (nestedView.Items.Count == 0)  
    74                     {  
    75                         TableCell cell = nestedView.ParentItem["ExpandColumn"];  
    76                         cell.Controls[0].Visible = false;  
    77                         nestedViewItem.Visible = false;  
    78                     }  
    79                     if (nestedView.HasDetailTables)  
    80                     {  
    81                         HideExpandColumnRecursive(nestedView);  
    82                     }  
    83                 }  
    84             }  
    85         }   
    86     }  
    87 }  
    88  

    Any suggestions?
  2. Veli
    Admin
    Veli avatar
    2002 posts

    Posted 10 Jul 2008 Link to this post

    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
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. digitall
    digitall avatar
    169 posts
    Member since:
    Jun 2006

    Posted 10 Jul 2008 Link to this post

    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!
  5. Joyce
    Joyce avatar
    7 posts
    Member since:
    Oct 2006

    Posted 19 Aug 2008 Link to this post

    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?

  6. Yavor
    Admin
    Yavor avatar
    11 posts

    Posted 20 Aug 2008 Link to this post

    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.
  7. Yuvika
    Yuvika avatar
    36 posts
    Member since:
    Mar 2009

    Posted 16 Jun 2010 Link to this post

    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
  8. Yavor
    Admin
    Yavor avatar
    11 posts

    Posted 16 Jun 2010 Link to this post

    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.
  9. Yuvika
    Yuvika avatar
    36 posts
    Member since:
    Mar 2009

    Posted 16 Jun 2010 Link to this post

    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
  10. Yavor
    Admin
    Yavor avatar
    11 posts

    Posted 17 Jun 2010 Link to this post

    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
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017