I have a RadGrid that contains a template column in which I've put two image buttons for edit and delete actions.
<telerik:GridTemplateColumn HeaderText="Actions">
<ItemTemplate>
<asp:ImageButton ID="btnEdit" runat="server" ImageUrl="~/images/icon_edit.png" style="display: inline-block" ToolTip="Edit" /> <asp:ImageButton ID="btnDelete" runat="server" ImageUrl="~/images/icon_delete.png" style="display: inline-block" ToolTip="Delete" />
</ItemTemplate>
</telerik:GridTemplateColumn>
How would get the value of the first cell of the row (datafield = "User_ID") when I click on the "delete" button?
Step 1.
Go to the Radgrid itself and edit the field DataKeyNames="" (under MasterTableView) and add the datafield you are pulling:
<MasterTableView ... DataKeyNames="User_ID">
Step 2. Edit the CommandName="" property of the Imagebuttons located in the grid:
<asp:ImageButton ID="btnDelete" runat="server" style="display: inline-block" ToolTip="Delete" CommandName="dosomething"/>
Create the following method for your Radgrid and add this code:
protected void RadGrid1_ItemCommand(object sender, Telerik.Web.UI.GridCommandEventArgs e)
{
if (e.CommandName == "dosomething")
{
//Use a line of code here to save that User_ID that you want from the first column
theUserId = e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["User_ID"];
}
}
Make sure theUserId = the same Type (int,double,dec...) as the field it's pulling from or you will have to parse it:
theUserId = Int.Parse(e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["User_ID"]);
Let me know if you need more help.