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

Setting ParentItem

1 Answer 40 Views
Grid
This is a migrated thread and some comments may be shown as answers.
JP
Top achievements
Rank 1
JP asked on 24 Jun 2013, 02:08 PM
Hello,

I want to add a column that works like a GridEditCommandColumn but using a GridButtonColumn. This works but with one problem. The editor opens like in insert mode, but it should open below the current row where the user clicked the command.
Here is my approach:

In the GriItemCommand event handler, I check if my command was clicked and save the internal id (of the database record) of the row:
private void GridItemCommand(object sender, GridCommandEventArgs e)
      {
          if (e.CommandName == "MyCommand")
         {
            this.mycommand = true;
            this.currentSelection = int.Parse(((GridDataItem)(e.Item)).EditFormItem.ParentItem[Grid.IdColumnUniqueName].Text);
            this.parentItem = ((GridDataItem)(e.Item)).EditFormItem.ParentItem;
         }
      }

In the ItemDataBound event, I initialize the control which should be displayed (it gets the id of the row I saved to this.currentSelection.
In OnPreRender I call this code to display the editor:

Grid.MasterTableView.IsItemInserted = true;
Grid.Rebind();

While the editor is opened with the correct object, it is opened like insert mode (at top) and not below the clicked row. How can I tell the GridItem to open below the correct row?

Thanks!

Edit: I'm using GridEditFormType.Template as EditFormType
And I have already a GridEditCommandColumn in my grid and since you can only have one, I have to use a different apporach like above.

1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 25 Jun 2013, 10:52 AM
Hi JP,

I'm not sure about your requirement.I guess you want to add a ButtonColumn for Edit instead of GridEditCommandColumn .Here is a code snippet i have tried using GridButtonColumn as Edit. Simply Set the CommandName=Edit and the edit form will be shown.

ASPX:
<telerik:RadGrid ID="RadGrid1" runat="server"  AutoGenerateColumns="False"
           AllowAutomaticInserts="True" AllowAutomaticUpdates="True" DataSourceID="SqlDataSource1">
           <MasterTableView CommandItemDisplay="Top">
               <Columns>                 
                   <telerik:GridBoundColumn UniqueName="EmployeeID" HeaderText="ID" DataField="EmployeeID">
                   </telerik:GridBoundColumn>
                   <telerik:GridBoundColumn UniqueName="FirstName" HeaderText="FirstName" DataField="FirstName">
                   </telerik:GridBoundColumn>
                   <telerik:GridBoundColumn UniqueName="LastName" HeaderText="LastName" DataField="LastName">
                   </telerik:GridBoundColumn>
                   <telerik:GridButtonColumn CommandName="Delete" Text="Delete" UniqueName="column">
                   </telerik:GridButtonColumn>
                   <telerik:GridButtonColumn CommandName="Edit" Text="Edit" UniqueName="Edit">
                   </telerik:GridButtonColumn>
               </Columns>
               <EditFormSettings EditFormType="Template">
                   <FormTemplate>
                       FirstName:
                       <asp:TextBox ID="TextBox2" Text='<%# Bind( "FirstName") %>' runat="server" TabIndex="8" >
                       </asp:TextBox>
                       Last Name:
                       <asp:TextBox ID="TextBox3" Text='<%# Bind( "LastName") %>' runat="server" TabIndex="9">
                       </asp:TextBox>
                       <asp:Button ID="btnUpdate" Text='<%# (Container is GridEditFormInsertItem) ? "Insert" : "Update" %>'
                           runat="server" CommandName='<%# (Container is GridEditFormInsertItem) ? "PerformInsert" : "Update" %>'>
                       </asp:Button
                       <asp:Button ID="btnCancel" Text="Cancel" runat="server" CausesValidation="False" />
                   </FormTemplate>
               </EditFormSettings>
           </MasterTableView>
       </telerik:RadGrid>

Thanks,
Shinu



Tags
Grid
Asked by
JP
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Share this question
or