Tuesday, December 4, 2012

RadGrid inside Radgrid hierarchy using Template Column

Problem:

I want to make RadGrid hierarchy using ItemTemplate.and I want commandItem display at top in Detail Grid just like Master Grid.

Solution:

Its technique is very simple,you have to put a <DetailTables> tag just after <MasterTableView> and make the relation of  Master and Detail, see the following example and watch for Bold text.But here I like to mention one thing that insert/update/delete events of Master and Detail grids are same and you have to differentiate that either insert/update/delete is called from Master or Detail. However NeedDataSource event is called when Master Grid is binned and DetailTableDataBind event is called when Detail table is binned.

<telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="False" PageSize="20"
        AllowSorting="True" AllowPaging="True" ShowStatusBar="True" GridLines="None"
        Skin="WebBlue" CellSpacing="0">
        <MasterTableView DataKeyNames="ParentID_PK" ClientDataKeyNames="ParentID_PK" CommandItemDisplay="Top">
        <DetailTables>
            <telerik:GridTableView DataKeyNames="DetailID_PK" ClientDataKeyNames="DetailID_PK"
                    Width="100%" runat="server" CommandItemDisplay="Top">
                <ParentTableRelation>
                    <telerik:GridRelationFields DetailKeyField="ParentID_FK" MasterKeyField="ParentID_PK">
                    </telerik:GridRelationFields>
                </ParentTableRelation>

                <Columns>

<%--here will be the columns of Detail table--%>

                </Columns>
            </telerik:GridTableView>
        </DetailTables>
        <Columns>



<%--here will be the columns of Master table--%>

        </Columns>
    </MasterTableView>
</telerik:RadGrid>

3 comments:

  1. hi. Thank you for your sharing. I have this structure on my web site. I have differentiated that either insert/update/delete is called from Master or Detail just like u said. but add, insert, delete doesn't work. can u share your server side code implementaion for insert,update? Thank you

    ReplyDelete
  2. How would you access the parent grid within the child. Say for a rebind?

    ReplyDelete