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

Have multiple GridButtonColumn CommandName="Select"

1 Answer 537 Views
Grid
This is a migrated thread and some comments may be shown as answers.
John
Top achievements
Rank 1
John asked on 17 Jan 2012, 05:54 PM
Can I have muliple GridButtonColumn CommandName="Select" Lines and have the OnSelectedIndexChanged event know which one I clicked?

I need to have different "buttons" on the same row and depending on the one they clicked have an event fire letting me know which button was clicked.

1 Answer, 1 is accepted

Sort by
0
Jayesh Goyani
Top achievements
Rank 2
answered on 17 Jan 2012, 07:55 PM
Hello,

<telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="false" OnItemDataBound="RadGrid1_ItemDataBound"
           OnNeedDataSource="RadGrid1_NeedDataSource" OnPreRender="RadGrid1_PreRender" OnItemCommand="RadGrid1_ItemCommand"
           AllowMultiRowSelection="true">
           <MasterTableView DataKeyNames="ID">
               <Columns>
                   <telerik:GridBoundColumn DataField="ID" HeaderText="ID" UniqueName="ID">
                   </telerik:GridBoundColumn>
                   <telerik:GridBoundColumn DataField="Name" HeaderText="Name" UniqueName="Name">
                   </telerik:GridBoundColumn>
                   <telerik:GridButtonColumn CommandName="SelectCommand" Text="SelectCommand">
                   </telerik:GridButtonColumn>
                   <telerik:GridButtonColumn CommandName="GetSelectStatus" Text="GetSelectStatus">
                   </telerik:GridButtonColumn>
               </Columns>
           </MasterTableView>
           <ClientSettings>
               <Selecting AllowRowSelect="true" />
           </ClientSettings>
       </telerik:RadGrid>
protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
       {
           dynamic data = new[] {
               new { ID = 1, Name ="name1"},
               new { ID = 2, Name = "Name2"},
               new { ID = 3, Name = "name3"},
               new { ID = 4, Name = "Name4"},
               new { ID = 5, Name = "name5"}
           };
           RadGrid1.DataSource = data;
       }
 
       protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
       {
            
       }
 
       protected void RadGrid1_PreRender(object sender, EventArgs e)
       {
           
       }
 
       protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
       {
           if (e.CommandName == "SelectCommand")
           {
               GridDataItem item = e.Item as GridDataItem;
               item.Selected = !item.Selected;
           }
           if (e.CommandName == "GetSelectStatus")
           {
               GridDataItem item = e.Item as GridDataItem;
               Response.Write(item.Selected.ToString());
           }
 
       }


Thanks,
Jayesh Goyani
Tags
Grid
Asked by
John
Top achievements
Rank 1
Answers by
Jayesh Goyani
Top achievements
Rank 2
Share this question
or