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

Bingding RadGrid 4 level using RadGrid1_DetailTableDataBind

1 Answer 90 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Hoi
Top achievements
Rank 1
Hoi asked on 26 Oct 2016, 12:44 AM

i have Radgrid with 4 level, in level1 and 2 i have using SqlDatasource (drop drop)

Even RadGrid1_DetailTableDataBind i want to bingding data source of level 3 and 4.

 

 <telerik:RadGrid ID="RadGrid1"   OnDetailTableDataBind="RadGrid1_DetailTableDataBind" runat="server" DataSourceID="SqlDataSource1" CellSpacing="0" GridLines="None">
                                        <MasterTableView DataSourceID="SqlDataSource1" DataKeyNames="id">
                                            <DetailTables>
                                                <telerik:GridTableView runat="server" DataKeyNames="id2" DataSourceID="SqlDataSource2">
                                                    <DetailTables>
                                                        <telerik:GridTableView runat="server">
                                                            <DetailTables>
                                                                <telerik:GridTableView runat="server"></telerik:GridTableView>
                                                            </DetailTables>
                                                        </telerik:GridTableView>
                                                    </DetailTables>
                                                    <ParentTableRelation>
                                                        <telerik:GridRelationFields MasterKeyField="id" DetailKeyField="id_cha2"></telerik:GridRelationFields>
                                                    </ParentTableRelation>
                                                </telerik:GridTableView>
                                            </DetailTables>
                                        </MasterTableView>
                                    </telerik:RadGrid>
                                   
                                    <asp:SqlDataSource runat="server" ID="SqlDataSource1" ConnectionString='<%$ ConnectionStrings:default %>' SelectCommand="sp_getproduct" SelectCommandType="StoredProcedure">
                                        <SelectParameters>
                                            <asp:SessionParameter SessionField="month" DefaultValue="9" Name="thang" Type="Int32"></asp:SessionParameter>
                                            <asp:QueryStringParameter QueryStringField="nsd" DefaultValue="cuongcp" Name="nsd" Type="String"></asp:QueryStringParameter>
                                            <asp:Parameter DefaultValue="1" Name="action" Type="Int32"></asp:Parameter>
                                        </SelectParameters>
                                    </asp:SqlDataSource>
                                    <asp:SqlDataSource runat="server" ID="SqlDataSource2" ConnectionString='<%$ ConnectionStrings:default %>' SelectCommand="sp_getproduct" SelectCommandType="StoredProcedure">
                                        <SelectParameters>
                                            <asp:SessionParameter SessionField="month" DefaultValue="9" Name="thang" Type="Int32"></asp:SessionParameter>
                                            <asp:QueryStringParameter QueryStringField="nsd" DefaultValue="cuongcp" Name="nsd" Type="String"></asp:QueryStringParameter>
                                            <asp:Parameter DefaultValue="2" Name="action" Type="Int32"></asp:Parameter>
                                        </SelectParameters>
                                    </asp:SqlDataSource>

 

and code behind

 protected void RadGrid1_DetailTableDataBind(object sender, Telerik.Web.UI.GridDetailTableDataBindEventArgs e)
        {
            if (e.DetailTableView.DataSourceID == "")
            {
                GridDataItem dataItem = (GridDataItem)e.DetailTableView.ParentItem;
                string OrderID = dataItem.GetDataKeyValue("id2").ToString();
                e.DetailTableView.DataSource = GetDataTable(OrderID);
               
            }

            if (e.DetailTableView.DataSourceID == "")
            {
                GridDataItem dataItem = (GridDataItem)e.DetailTableView.ParentItem;
                string id = dataItem.GetDataKeyValue("id3").ToString();
                e.DetailTableView.DataSource = GetDataTable_detailt(id);
            }
        }

but at level 4 error. plz  help me, thanks in advance

1 Answer, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 28 Oct 2016, 01:37 PM
Hello Tran,

I don't think that checking for an empty datasource string would be a good way to identify the tableview. It would be better if you just set names to each level. This way:
<telerik:RadGrid ID="RadGrid1"...>
    <MasterTableView Name="Master">
        <DetailTables>
            <telerik:GridTableView Name="Detail1">
                <DetailTables>
                    <telerik:GridTableView Name="DetailN"></telerik:GridTableView>
                </DetailTables>
            </telerik:GridTableView>
        </DetailTables>
 ...

Let me know whether this helps.

Regards,
Daniel
Telerik by Progress
Check out the new UI for ASP.NET Core, the most complete UI suite for ASP.NET Core development on the market, with 60+ tried-and-tested widgets, based on Kendo UI.
Tags
Grid
Asked by
Hoi
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Share this question
or