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

How to assign cs code for button in commandItemTemplate

3 Answers 62 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Venkatesh
Top achievements
Rank 1
Venkatesh asked on 15 Jan 2013, 12:56 PM
Hi,
I have a button added in commanditemtemplate.

<MasterTableView DataKeyNames="ProductNumber" ShowHeadersWhenNoRecords="true" CommandItemDisplay="Bottom" EnableNoRecordsTemplate="false" AutoGenerateColumns="false" EditMode="InPlace" CommandItemSettings-ShowRefreshButton="false" >
                  <CommandItemTemplate>                    
                        <asp:Button ID="btnAddItem" Text="Add New Item" runat="server" CommandName="InitInsert">
                        </asp:Button>
                    </CommandItemTemplate>
<columns>
</columns>

How to add the code behind for the btnAddItem?

Thanks

3 Answers, 1 is accepted

Sort by
0
Elliott
Top achievements
Rank 2
answered on 15 Jan 2013, 08:03 PM
what I did was to use a GridEditCommandCoumn
it opened a user control with an Add button (as well as textboxes, validators, etc)
did you try implementing an ItemCommand event handler and looking for InitInsert as the CommandName?
0
Venkatesh
Top achievements
Rank 1
answered on 16 Jan 2013, 02:55 AM
HI,
Thanks for the quick reply.
Could you please provide a sample code of how you achieved it( aspx and cs).
0
Shinu
Top achievements
Rank 2
answered on 16 Jan 2013, 04:45 AM
Hi,

You can check for the CommandName in ItemCommand event as shown below.
aspx:
<telerik:RadGrid ID="RadGrid2" AutoGenerateColumns="false" runat="server" OnItemCommand="RadGrid2_ItemCommand" DataSourceID="SqlDataSource2">
 <MasterTableView DataKeyNames="ProductNumber" ShowHeadersWhenNoRecords="true" CommandItemDisplay="Bottom" EnableNoRecordsTemplate="false" AutoGenerateColumns="false" EditMode="InPlace" CommandItemSettings-ShowRefreshButton="false" >
  <CommandItemTemplate>                   
     <asp:Button ID="btnAddItem" Text="Add New Item" runat="server" CommandName="InitInsert"></asp:Button>
  </CommandItemTemplate>
   <Columns>
     <telerik:GridBoundColumn DataField="Id" UniqueName="Id"></telerik:GridBoundColumn>
   </Columns>
 </MasterTableView>
</telerik:RadGrid>
C#:
protected void RadGrid2_ItemCommand(object sender, GridCommandEventArgs e)
{
    if (e.CommandName == "InitInsert")
    {
    }
}

Thanks,
Shinu
Tags
Grid
Asked by
Venkatesh
Top achievements
Rank 1
Answers by
Elliott
Top achievements
Rank 2
Venkatesh
Top achievements
Rank 1
Shinu
Top achievements
Rank 2
Share this question
or