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

How to bind master-nested-detail grid from objectDatasource

2 Answers 180 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Berkant Oral
Top achievements
Rank 1
Berkant Oral asked on 30 Oct 2012, 07:50 AM
Hi everyone

I can bind master-detail grid from objectDataSource like this;

<telerik:RadGrid ID="radGridOrderProduct" ShowStatusBar="True" DataSourceID="objDsCartProductList"<br>
    runat="server" Width="100%" AutoGenerateColumns="False" AllowSorting="True" AllowPaging="True"<br>
    GridLines="None" CellSpacing="0"><br>
    <PagerStyle Mode="NumericPages"></PagerStyle><br>
    <MasterTableView Width="100%" DataSourceID="objDsCartProductList" DataKeyNames="Id"<br>
        AllowMultiColumnSorting="True"><br>
        <NestedViewTemplate><br>
            <asp:Label ID="Label1" Text='<%#Eval("Id") %>' Visible="false" runat="server" /><br>
            <telerik:RadGrid runat="server" ID="radGridOrderProductDetail" DataSourceID="objDsCartProductList"<br>
                GridLines="None"><br>
                <MasterTableView ShowHeader="true" AutoGenerateColumns="False" runat="server" HierarchyLoadMode="ServerOnDemand"<br>
                    DataSourceID="objDsCartProductList"><br>
                    <Columns><br>
                        <telerik:GridTemplateColumn><br>
                            <ItemTemplate><br>
                                <asp:Label ID="lblTotalPrice" runat="server" Font-Bold="true" Font-Size="14px" Text='<%#                (Eval("TotalPrice").ToString()) %>'></asp:Label><br>
                                <span>TL</span><br>
                            </ItemTemplate><br>
                        </telerik:GridTemplateColumn><br>
                    </Columns><br>
                </MasterTableView><br>
            </telerik:RadGrid><br>
            <asp:ObjectDataSource ID="objDsCartProductList" runat="server" SelectMethod="GetOrderProductListWithOrderId"<br>
                TypeName="MatriksEshop.Web.UserControls.Order.Control.BaseUserControl"><br>
                <SelectParameters><br>
                    <asp:ControlParameter ControlID="Label1" Name="orderId" PropertyName="Text" Type="String" /><br>
                </SelectParameters><br>
            </asp:ObjectDataSource><br>
        </NestedViewTemplate><br>
        <CommandItemSettings ExportToPdfText="Export to PDF"></CommandItemSettings><br>
        <RowIndicatorColumn Visible="True" FilterControlAltText="Filter RowIndicator column"><br>
        </RowIndicatorColumn><br>
        <ExpandCollapseColumn Visible="True"><br>
        </ExpandCollapseColumn><br>
        <Columns><br>
            <telerik:GridTemplateColumn><br>
                <HeaderTemplate><br>
                    <asp:Label ID="lblTotalPrices" runat="server" Text="<%$ Resources:Eshop, ProductTotal%>"></asp:Label><br>
                </HeaderTemplate><br>
                <ItemTemplate><br>
                    <asp:Label ID="lblTotalPrice" runat="server" Font-Bold="true" Font-Size="14px" Text='<%#(Eval("TotalPrice")) %>'></asp:Label><br>
                    <span>TL</span><br>
                </ItemTemplate><br>
            </telerik:GridTemplateColumn><br>
        </Columns><br>
        <EditFormSettings><br>
            <EditColumn FilterControlAltText="Filter EditCommandColumn column"><br>
            </EditColumn><br>
        </EditFormSettings><br>
    </MasterTableView><br>
    <FilterMenu EnableTheming="True"><br>
        <CollapseAnimation Duration="200" Type="OutQuint" /><br>
    </FilterMenu><br>
</telerik:RadGrid><br>
<asp:ObjectDataSource ID="objDsCartProductList" runat="server" SelectMethod="GetOrderListWithMemberId"<br>
    TypeName="MatriksEshop.Web.UserControls.Order.Control.BaseUserControl"></asp:ObjectDataSource>


But I want to detail level in this grid. I want to bind this grid with radGridOrderProductDetail dataKeyNames. How can i do this?

Best Regards

2 Answers, 1 is accepted

Sort by
0
Accepted
Angel Petrov
Telerik team
answered on 02 Nov 2012, 09:50 AM
Hello Berkant,

If you want to use a detail table you have to set the parent-child relations between the two grids. In order to do that you have to set the DataKeyNames of the RadGrid which is in the NestedViewTeplate so the most inner grid can relate properly. In the following code snippet I demonstrate this approach:
<telerik:RadGrid ID="radGridOrderProduct" ShowStatusBar="True" DataSourceID="objDsCartProductList"
        runat="server" Width="100%" AutoGenerateColumns="False" AllowSorting="True" AllowPaging="True"
        GridLines="None" CellSpacing="0">
        <PagerStyle Mode="NumericPages"></PagerStyle>
        <MasterTableView Width="100%" DataSourceID="objDsCartProductList" DataKeyNames="Id"
            AllowMultiColumnSorting="True">
            <NestedViewTemplate>
                <asp:Label ID="Label1" Text='<%#Eval("Id") %>' Visible="false" runat="server" />
                <telerik:RadGrid runat="server" ID="radGridOrderProductDetail" DataSourceID="objDsCartProductList"
                    GridLines="None">
                    <MasterTableView ShowHeader="true" AutoGenerateColumns="False" runat="server" HierarchyLoadMode="ServerOnDemand"
                        DataSourceID="objDsCartProductList" DataKeyNames="YourKeyNameWithWhichYouWillRelateTheGrids">
                        <DetailTables>
                            <telerik:GridTableView DataSourceID="SomeDataSource" DataKeyNames="SomeKeyName" runat="server">
                                <ParentTableRelation>
                                    <telerik:GridRelationFields DetailKeyField="YourKeyNameWithWhichYouWillRelateTheGrids"
                                        MasterKeyField="YourKeyNameWithWhichYouWillRelateTheGrids"></telerik:GridRelationFields>
                                </ParentTableRelation>
                                <Columns>
                                    Here should stand you columns
                                </Columns>
                            </telerik:GridTableView>
                        </DetailTables>
                        <Columns>
                            <telerik:GridTemplateColumn>
                                <ItemTemplate>
                                    <asp:Label ID="lblTotalPrice" runat="server" Font-Bold="true" Font-Size="14px" Text='<%#                (Eval("TotalPrice").ToString()) %>'></asp:Label>
                                    <span>TL</span>
                                </ItemTemplate>
                            </telerik:GridTemplateColumn>
                        </Columns>
                    </MasterTableView>
                </telerik:RadGrid>
                <asp:ObjectDataSource ID="objDsCartProductList" runat="server" SelectMethod="GetOrderProductListWithOrderId"
                    TypeName="MatriksEshop.Web.UserControls.Order.Control.BaseUserControl">
                    <SelectParameters>
                        <asp:ControlParameter ControlID="Label1" Name="orderId" PropertyName="Text" Type="String" />
                    </SelectParameters>
                </asp:ObjectDataSource>
            </NestedViewTemplate>
            <CommandItemSettings ExportToPdfText="Export to PDF"></CommandItemSettings>
            <RowIndicatorColumn Visible="True" FilterControlAltText="Filter RowIndicator column">
            </RowIndicatorColumn>
            <ExpandCollapseColumn Visible="True">
            </ExpandCollapseColumn>
            <Columns>
                <telerik:GridTemplateColumn>
                    <HeaderTemplate>
                        <asp:Label ID="lblTotalPrices" runat="server" Text="<%$ Resources:Eshop, ProductTotal%>"></asp:Label>
                    </HeaderTemplate>
                    <ItemTemplate>
                        <asp:Label ID="lblTotalPrice" runat="server" Font-Bold="true" Font-Size="14px" Text='<%#(Eval("TotalPrice")) %>'></asp:Label>
                        <span>TL</span>
                    </ItemTemplate>
                </telerik:GridTemplateColumn>
            </Columns>
            <EditFormSettings>
                <EditColumn FilterControlAltText="Filter EditCommandColumn column">
                </EditColumn>
            </EditFormSettings>
        </MasterTableView>
        <FilterMenu EnableTheming="True">
            <CollapseAnimation Duration="200" Type="OutQuint" />
        </FilterMenu>
    </telerik:RadGrid>
    <asp:ObjectDataSource ID="objDsCartProductList" runat="server" SelectMethod="GetOrderListWithMemberId"
        TypeName="MatriksEshop.Web.UserControls.Order.Control.BaseUserControl"></asp:ObjectDataSource>
Also I suggest that you take a look at the following demo which almost replicates your scenario and this help topic in which using declarative relations is described.

All the best,
Angel Petrov
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Berkant Oral
Top achievements
Rank 1
answered on 05 Nov 2012, 07:42 AM
Hello,

it is working fine. 

Thanks for your answer

Best Regards

Emrah Özgüner
Tags
Grid
Asked by
Berkant Oral
Top achievements
Rank 1
Answers by
Angel Petrov
Telerik team
Berkant Oral
Top achievements
Rank 1
Share this question
or