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

[Solved] Hierarchy Grid Problem

2 Answers 114 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Nabeel
Top achievements
Rank 1
Nabeel asked on 25 Apr 2009, 05:36 PM
Hello,
I just download telerik tools for Ajax Asp.net Controls, I'm using RadGrid, and binding it inside the code to my custom object, the first level of hierarchy working fine and I can see the data, once I select a record and get it is id I rebind the data from the same table using parent ID, the detailed GridTableView is not binding any data even I can see the data comming from my object.
here is the code below the asp.net and code behind:

 <telerik:RadGrid  OnDetailTableDataBind="RadGrid1_DetailTableDataBind"  ID="RadGrid1" runat="server" AllowFilteringByColumn="True"
        AllowPaging="True" AllowSorting="True" GridLines="None" ShowGroupPanel="True"
        Skin="Forest" AutoGenerateColumns="False">
        
        <mastertableview datakeynames="CabinetID">
            <DetailTables>
                <telerik:GridTableView runat="server">
                    <RowIndicatorColumn>
                        <HeaderStyle Width="20px" />
                    </RowIndicatorColumn>
                    <DetailTables>
                        <telerik:GridTableView DataKeyNames="CabinetID" Name="Drawer" Width="100%" runat="server">
                        <Columns>
                                    <telerik:GridBoundColumn SortExpression="Name" HeaderText="Name" HeaderButtonType="TextButton"
                                        DataField="Name">
                                    </telerik:GridBoundColumn>
                                    <telerik:GridBoundColumn SortExpression="Description" HeaderText="Discription" HeaderButtonType="TextButton"
                                        DataField="Discription">
                                    </telerik:GridBoundColumn>
                               
                                </Columns>
                            <RowIndicatorColumn>
                                <HeaderStyle Width="20px" />
                            </RowIndicatorColumn>
                            <ExpandCollapseColumn>
                                <HeaderStyle Width="20px" />
                            </ExpandCollapseColumn>
                        </telerik:GridTableView>
                    </DetailTables>
                    <ExpandCollapseColumn Visible="True">
                    </ExpandCollapseColumn>
                </telerik:GridTableView>
            </DetailTables>
            <expandcollapsecolumn visible="True">
            </expandcollapsecolumn>
            <Columns>
                <telerik:GridBoundColumn DataField="Name" HeaderText="Name"
                    SortExpression="Name" UniqueName="Name">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="Description" HeaderText="Description"
                    SortExpression="Description" UniqueName="Description">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="CreateDate" DataType="System.DateTime"
                    HeaderText="CreateDate" SortExpression="CreateDate" UniqueName="CreateDate">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="UserID" HeaderText="UserID"
                    SortExpression="UserID" UniqueName="UserID">
                </telerik:GridBoundColumn>
            </Columns>
        </mastertableview>
        <ClientSettings AllowDragToGroup="True">
            <Scrolling AllowScroll="True" UseStaticHeaders="True" />
        </ClientSettings>
        
    </telerik:RadGrid>

        protected void RadGrid1_DetailTableDataBind(object source,
                      GridDetailTableDataBindEventArgs e)
        {
            // make sure this is this is the right detail table
            if (e.DetailTableView.DataSourceID == "")
            {
                GridDataItem masterItem = (GridDataItem)e.DetailTableView.ParentItem;
                MyObject.UserID = HttpContext.Current.User.Identity.Name;
                MyObject.ID = Convert.ToInt32(masterItem.GetDataKeyValue("ID"));
               BusinessObject[] list = service.GetHierarchy(MyObject);
                e.DetailTableView.DataSource = list;
            }
        }


2 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 27 Apr 2009, 04:38 AM
Hi Nabeel,

 Make sure that you are accessing the correct DataKeyName. Here in the above given aspx code you have set the DataKeyName as 'CabinetID' and in the code behind you are accessing the key value as 'ID'.

CS:
 protected void RadGrid1_DetailTableDataBind(object source, 
                      GridDetailTableDataBindEventArgs e) 
        { 
            // make sure this is this is the right detail table 
            if (e.DetailTableView.DataSourceID == ""
            { 
                GridDataItem masterItem = (GridDataItem)e.DetailTableView.ParentItem; 
                MyObject.UserID = HttpContext.Current.User.Identity.Name; 
                MyObject.ID = Convert.ToInt32(masterItem.GetDataKeyValue("CabinetID")); 
               BusinessObject[] list = service.GetHierarchy(MyObject); 
                e.DetailTableView.DataSource = list; 
            } 
        } 
 

Go through the online demo which demonstrates how to dynamically bind a hierarchical Grid.
Programmatic Binding

Shinu.
0
Nabeel
Top achievements
Rank 1
answered on 27 Apr 2009, 12:52 PM
The Datakeyname is correct CabinetID but I change it in this forum for security purpose.
Tags
Grid
Asked by
Nabeel
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Nabeel
Top achievements
Rank 1
Share this question
or