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

[Solved] Heirarchy detail table added on runtime

4 Answers 92 Views
Grid
This is a migrated thread and some comments may be shown as answers.
DragonBall
Top achievements
Rank 1
DragonBall asked on 07 Sep 2009, 08:56 AM
I have Tables Customer and Two nested Table(Order and OrderDetais). the problem is i have to
add the detail table (GridTableView) if the item is expanded
so far i solve the Customer To display the Order Table but when i try to expand
Order table to display The OrderDetails it wont show up how do i do this

Note: GridTableView will must be added only/during item expand

Customer
  Order
    OrderDetails       
 protected void RadGrid1_DetailTableDataBind(object source, GridDetailTableDataBindEventArgs e) 
    { 
        if (e.DetailTableView.DataSourceID == "") 
        { 
 
            SqlDataSource2.SelectParameters["CustomerID"].DefaultValue = e.DetailTableView.ParentItem.GetDataKeyValue("CustomerID").ToString(); 
            e.DetailTableView.DataSource = SqlDataSource2
            GridTableView tableViewOrders = new GridTableView(RadGrid1); 
             
            tableViewOrders.DataSource = SqlDataSource3
            tableViewOrders.Width = Unit.Percentage(100); 
            tableViewOrders.AutoGenerateColumns = true
            tableViewOrders.DataKeyNames = new string[] { "OrderID" }; 
            tableViewOrders.HierarchyLoadMode = GridChildLoadMode.ServerOnDemand; 
            GridRelationFields relationFields = new GridRelationFields(); 
             
            relationFields.MasterKeyField = "OrderID"
            relationFields.DetailKeyField = "OrderID"
            tableViewOrders.ParentTableRelation.Add(relationFields); 
             
            e.DetailTableView.DetailTables.Add(tableViewOrders); 
            e.DetailTableView.ID = "NestedOrder"
             
        } 
         
    } 
 <asp:SqlDataSource ID="SqlDataSource1" 
ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>" 
            ProviderName="System.Data.SqlClient" 
            SelectCommand="SELECT * FROM Customers" runat="server"></asp:SqlDataSource> 
<asp:SqlDataSource ID="SqlDataSource2" 
ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>" 
            ProviderName="System.Data.SqlClient" 
            SelectCommand="SELECT * FROM Orders Where CustomerID = @CustomerID" runat="server"
            <SelectParameters> 
                <asp:Parameter Name="CustomerID" Type="string" /> 
            </SelectParameters> 
        </asp:SqlDataSource> 
<asp:SqlDataSource ID="SqlDataSource3" 
ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>" 
            ProviderName="System.Data.SqlClient" 
            SelectCommand="SELECT * FROM [Order Details] where OrderID = @OrderID" runat="server"
            <SelectParameters> 
                <asp:Parameter Name="OrderID" Type="Int32" /> 
            </SelectParameters> 
        </asp:SqlDataSource> 


   <telerik:RadGrid id="RadGrid1" DataSourceID="SqlDataSource1"   
             ShowStatusBar="true" runat="server" AllowPaging="True"  
        AllowSorting="True" AllowAutomaticUpdates="True"  
        OnItemCommand="RadGrid1_ItemCommand" OnDetailTableDataBind="RadGrid1_DetailTableDataBind"
                <MasterTableView PageSize="10" DataKeyNames="CustomerID"
                
           <DetailTables> 
                <telerik:GridTableView></telerik:GridTableView> 
               
            </DetailTables> 
            
<ExpandCollapseColumn Visible="True"></ExpandCollapseColumn> 
        </MasterTableView> 
             
 
         
    <ClientSettings EnableRowHoverStyle="true"
     
    <Selecting AllowRowSelect="true" /> 
    <ClientEvents OnRowDblClick="RowDblClick" /> 
   </ClientSettings> 
    </telerik:RadGrid> 

4 Answers, 1 is accepted

Sort by
0
Martin
Telerik team
answered on 07 Sep 2009, 03:15 PM
Hello Manuel,

I prepared a sample project demonstrating the required behaviour.

If I still miss something or you have different intention please don't hesitate to contact us again with more details.

Best regards,
Martin
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
DragonBall
Top achievements
Rank 1
answered on 07 Sep 2009, 11:21 PM
thank you for the quick reply. i will be testing this
0
DragonBall
Top achievements
Rank 1
answered on 08 Sep 2009, 12:02 AM
hello there. the problem is not yet solved since you already added the Gridtableview, it must be added on runtime together with the reltionship

<DetailTables> 
                    <telerik:GridTableView runat="server" Name="Orders"
                        <DetailTables> 
                            <telerik:GridTableView runat="server" Name="OrderDetails"
                            </telerik:GridTableView> 
                        </DetailTables> 
                    </telerik:GridTableView> 
                </DetailTables> 

the GridTableView must be added only when it is expanded on runtime not on design time. my goal is to add multiple detailtable during runtime. is that possible?



0
Martin
Telerik team
answered on 08 Sep 2009, 04:00 PM
Hello Manuel,

If you don't have the GridTableView declared in the markup you can not expand the GridExpandColumn because there will be nothing to be expanded. From your first post I saw that you have declared the first child table and that is why you managed to achieve the desired functionality for it. You should use the same approach for the second child table as I proposed in my sample project.

Hope this helps. 

Regards,
Martin
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
Grid
Asked by
DragonBall
Top achievements
Rank 1
Answers by
Martin
Telerik team
DragonBall
Top achievements
Rank 1
Share this question
or