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

Load Details table

2 Answers 41 Views
Grid
This is a migrated thread and some comments may be shown as answers.
jen
Top achievements
Rank 1
jen asked on 23 Feb 2015, 03:09 PM
I can't seem to get my detail table to load properly. I am using the NeedDataSource and DetailTableDataBind events and entity framework.
The main grid loads as expected after the NeedDataSource event, and in the DetailTableDataBind I can see at least one item in the list being set as the datasource. 
However after clicking to expand the row, the detail table shows no results.


        <telerik:RadGrid ID="StarTranPIsGrid" runat="server" AutoGenerateColumns="false" 
                OnNeedDataSource="StarTranPIsGrid_NeedDataSource"  OnDetailTableDataBind="StarTranPIsGrid_DetailTableDataBind" >
             <MasterTableView DataKeyNames="ID" HierarchyLoadMode="ServerBind" EnableHierarchyExpandAll="true">
                <Columns> 
                    <telerik:GridBoundColumn UniqueName="ID" DataField="ID" Visible="false" />
                    <telerik:GridBoundColumn UniqueName="InvoiceNumber" DataField="InvoiceNumber" HeaderText="Invoice Number" />
                    <telerik:GridBoundColumn UniqueName="ShipDate" DataField="ShipDate" HeaderText="Ship Date" />
                </Columns>
                 <DetailTables>
                     <telerik:GridTableView DataKeyNames="StarTranPIID, SequenceNum">
                         <DetailItemTemplate>
                             <telerik:GridTableView DataKeyNames="StarTranID,SequenceNum" Width="100%" runat="server">
                                 <Columns>
                                    <telerik:GridBoundColumn UniqueName="PartNumber" DataField="PartNumber" HeaderText="Part Number" />
                                    <telerik:GridBoundColumn UniqueName="OrderNumber" DataField="OrderNumber" HeaderText="Order Number" />
                                    <telerik:GridBoundColumn UniqueName="QtyOrder" DataField="QtyOrder" HeaderText="Qty Order" />
                                    <telerik:GridBoundColumn UniqueName="QtyShip" DataField="QtyShip" HeaderText="Qty Ship" />
                                    <telerik:GridBoundColumn UniqueName="ReferenceNumber" DataField="ReferenceNumber" HeaderText="Reference Number" />
                                    <telerik:GridBoundColumn UniqueName="ShipmentNumber" DataField="ShipmentNumber" HeaderText="ShipmentNumber" />
                                 </Columns>
                             </telerik:GridTableView>
                         </DetailItemTemplate>
                     </telerik:GridTableView>
                 </DetailTables>
            </MasterTableView>
        </telerik:RadGrid>


    protected void StarTranPIsGrid_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
    {
        int ID = (int)Session["ShipperDetailsID"];
        StarTran Transaction = context.StarTrans.FirstOrDefault(s => s.ID == ID);
        if (Transaction != null)
            StarTranPIsGrid.DataSource = Transaction.StarTranPIs.ToList();
    }

    protected void StarTranPIsGrid_DetailTableDataBind(object sender, Telerik.Web.UI.GridDetailTableDataBindEventArgs e)
    {
        GridDataItem dataItem = (GridDataItem)e.DetailTableView.ParentItem;
        int ID = (int)dataItem.GetDataKeyValue("ID");

        List<StarTranPIPart> children = context.StarTranPIs.First(t => t.ID == ID).StarTranPIParts.ToList();
        e.DetailTableView.DataSource = children; //children contains at least one item!
    }


I've been following the demos and documentation:
http://demos.telerik.com/aspnet-ajax/grid/examples/data-binding/programmatic-hierarchy/defaultcs.aspx
http://www.telerik.com/help/aspnet-ajax/grid-binding-hierarchical-grids.html
http://www.telerik.com/help/aspnet-ajax/grid-hierarchical-data-binding-using-detailtabledatabind.html


Can anyone provide any insight into what I am missing to get my details table to populate?

2 Answers, 1 is accepted

Sort by
0
jen
Top achievements
Rank 1
answered on 25 Feb 2015, 02:12 PM
I heard back from support. The problem was my details table was nested incorrectly. The   <DetailItemTemplate> part was not needed.

  <DetailTables>
                     <telerik:GridTableView DataKeyNames="StarTranPIID, SequenceNum">
                         <DetailItemTemplate>
                             <telerik:GridTableView DataKeyNames="StarTranID,SequenceNum" Width="100%" runat="server">
0
Accepted
Viktor Tachev
Telerik team
answered on 25 Feb 2015, 03:31 PM
Hello Jen,

Try to modify the markup like shown below and the DetailTable should show the items as expected:

<telerik:RadGrid ID="StarTranPIsGrid" runat="server" AutoGenerateColumns="false"
    OnNeedDataSource="StarTranPIsGrid_NeedDataSource" OnDetailTableDataBind="StarTranPIsGrid_DetailTableDataBind">
    <MasterTableView DataKeyNames="ID" HierarchyLoadMode="ServerBind" EnableHierarchyExpandAll="true">
        <Columns>
            <telerik:GridBoundColumn UniqueName="ID" DataField="ID" Visible="false" />
            <telerik:GridBoundColumn UniqueName="InvoiceNumber" DataField="InvoiceNumber" HeaderText="Invoice Number" />
            <telerik:GridBoundColumn UniqueName="ShipDate" DataField="ShipDate" HeaderText="Ship Date" />
        </Columns>
        <DetailTables>
            <telerik:GridTableView DataKeyNames="StarTranPIID, SequenceNum">
                <Columns>
                    <telerik:GridBoundColumn UniqueName="PartNumber" DataField="PartNumber" HeaderText="Part Number" />
                    <telerik:GridBoundColumn UniqueName="OrderNumber" DataField="OrderNumber" HeaderText="Order Number" />
                    <telerik:GridBoundColumn UniqueName="QtyOrder" DataField="QtyOrder" HeaderText="Qty Order" />
                    <telerik:GridBoundColumn UniqueName="QtyShip" DataField="QtyShip" HeaderText="Qty Ship" />
                    <telerik:GridBoundColumn UniqueName="ReferenceNumber" DataField="ReferenceNumber" HeaderText="Reference Number" />
                    <telerik:GridBoundColumn UniqueName="ShipmentNumber" DataField="ShipmentNumber" HeaderText="ShipmentNumber" />
                </Columns>
            </telerik:GridTableView>
        </DetailTables>
    </MasterTableView>
</telerik:RadGrid>



Regards,
Viktor Tachev
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
Grid
Asked by
jen
Top achievements
Rank 1
Answers by
jen
Top achievements
Rank 1
Viktor Tachev
Telerik team
Share this question
or