This is a migrated thread and some comments may be shown as answers.
Nested GridTableView Question
3 Answers 43 Views
This is a migrated thread and some comments may be shown as answers.
max
Top achievements
Rank 1
max asked on 13 Jan 2011, 04:47 PM
Hi, I am fairly new to asp.net.  I am trying to build a 3 level deep hierarchy grid.  I am using linq and joining multiple tables.  The problem I am running into is at level 3, I want to insert a record, into that grid, and i want to use a custom edit form template.  Which I want to have an insert and cancel button.  How do i map these buttons to send Telerik.Web.UI.GridCommandEventArgs e, so that I know which grid is doing the insert?
Basically I want Insert and cancel buttons to work the same way as if I used a standard automatic insert mode.


<telerik:RadGrid ID="RadGrid1" runat="server" DataSourceID="LinqDataSource1" GridLines="None"  OnDeleteCommand="RadGrid1_ItemDeleted"
     AllowAutomaticDeletes="True"
      OnItemInserted="RadGrid1_ItemInserted" OnInsertCommand="RadGrid1_InsertCommand"
     >
        <MasterTableView DataSourceID="LinqDataSource1" DataKeyNames="day_id" AutoGenerateColumns="false" Name="Days">
                                <ExpandCollapseColumn Visible="True">
            </ExpandCollapseColumn>
            <Columns>
            <telerik:GridBoundColumn DataField="day_id" Visible="false"></telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="day_name" HeaderText="Day" ></telerik:GridBoundColumn>
            </Columns>

            <DetailTables>
                <telerik:GridTableView DataSourceID="LinqDataSource2" DataKeyNames="day_group_id" Name="Groups" AutoGenerateColumns="false" AllowPaging="True">
                    <ParentTableRelation>
                        <telerik:GridRelationFields DetailKeyField="day_id" MasterKeyField="day_id" />
                    </ParentTableRelation>
                    <Columns>
                        <telerik:GridBoundColumn DataField="day_group_id" Visible="false"></telerik:GridBoundColumn>
                        <telerik:GridBoundColumn DataField="group_id" Visible="false"></telerik:GridBoundColumn>
                        <telerik:GridBoundColumn DataField="group_name" HeaderText="Group Name:"></telerik:GridBoundColumn>
                        <telerik:GridBoundColumn DataField="physician_selected" HeaderText="Physician Name"></telerik:GridBoundColumn>
                    </Columns>
                    <DetailTables>
                        <telerik:GridTableView  DataSourceID="LinqDataSource3" DataKeyNames="day_group_user_id" Name="Users" AutoGenerateColumns="false" CommandItemDisplay="Top" AllowAutomaticDeletes="false">
                            <ParentTableRelation>
                                <telerik:GridRelationFields DetailKeyField="day_group_id" MasterKeyField="day_group_id" />
                            </ParentTableRelation>
                            <Columns>
                                <telerik:GridBoundColumn DataField="fname" HeaderText="First Name:"></telerik:GridBoundColumn>
                                <telerik:GridBoundColumn DataField="lname" HeaderText="Last Name:"></telerik:GridBoundColumn>
                                <telerik:GridBoundColumn DataField="email" HeaderText="Email:"></telerik:GridBoundColumn>
                                <telerik:GridButtonColumn ConfirmText="Remove this user?" ConfirmDialogType="RadWindow"
                                     ConfirmTitle="Delete" ButtonType="ImageButton" CommandName="Delete"  CommandArgument="day_group_user_id"/>
                            </Columns>
 <EditFormSettings  CaptionFormatString="Edit EmployeeID: {0}"
                CaptionDataField="EmployeeID" EditFormType="Template">
                <FormTemplate>
       
       
                                <telerik:RadComboBox runat="server" DataSourceID="LinqDataSource4"
                                  DataTextField="Name"  DataValueField="user_id" AllowCustomText="false" Width="500">
                                 <HeaderTemplate>
           <table width="499px">
           <tr>
           <td width="30%">Name</td><td width="70%">Email</td>
           </tr>
           </table>
        </HeaderTemplate>
        <ItemTemplate>
        <table  width="499px">
        <tr>
        <td width="30%"> <%# DataBinder.Eval(Container.DataItem, "name") %>
        </td>
        <td width="70%">
         <%# DataBinder.Eval(Container.DataItem, "email") %>
        </td>
        </tr>
        </table>

        </ItemTemplate>

                                 </telerik:RadComboBox>
                                 <br />
                                 <asp:linkbutton ID="Linkbutton1" runat="server" OnClick="LinkButton1_Click">Insert</asp:linkbutton>
                                 <asp:linkbutton ID="Linkbutton2" runat="server">Cancel</asp:linkbutton>

                </FormTemplate>
            </EditFormSettings>


   


                         </telerik:GridTableView>
                    </DetailTables>
                </telerik:GridTableView>
            </DetailTables>
        </MasterTableView>
    </telerik:RadGrid>

3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 1
answered on 14 Jan 2011, 07:19 AM
Hello MAx,

In order to achieve this, you can set appropriate CommandName for insert and cancel button like below.

ASPX:
 <FormTemplate>
       <asp:LinkButton ID="Linkbutton1" runat="server" CommandName="PerformInsert" >Insert
       </asp:LinkButton>
       <asp:LinkButton ID="Linkbutton2" runat="server" CommandName="Cancel">Cancel
       </asp:LinkButton>
 </FormTemplate>

And in InserCommand you can differentiate item in each hierarchy using the name of TableView.

C#:
protected void RadGrid1_InsertCommand(object sender, GridCommandEventArgs e)
   {
       if (e.Item.OwnerTableView.Name == "Users")//check with name of TableView
       {
           // code to insert record
       }
   }

Thanks,
Princy.
0
max
Top achievements
Rank 1
answered on 14 Jan 2011, 04:25 PM
Thank you.  So appropriate command means "insert" and "cancel"
0
max
Top achievements
Rank 1
answered on 14 Jan 2011, 04:45 PM
Okay.  I got it.  Thank you very much.
Tags
Grid
Asked by
max
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 1
max
Top achievements
Rank 1
Share this question
or