Refer this code and check Id and name in delete event of ImageButton.
HTML
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView1" HeaderStyle-BackColor="#3AC0F2" DataKeyNames="Id,Name"
HeaderStyle-ForeColor="White" runat="server" AutoGenerateColumns="false">
<Columns>
<asp:BoundField DataField="Id" HeaderText="Id" ItemStyle-Width="30" />
<asp:BoundField DataField="Name" HeaderText="Name" ItemStyle-Width="150" />
<asp:BoundField DataField="Country" HeaderText="Country" ItemStyle-Width="150" />
<asp:TemplateField HeaderText="Delete">
<ItemTemplate>
<asp:ImageButton ID="lnkdelete" ImageUrl="~/Images/del.png" Width="20" Height="20"
runat="server" OnClick="lnkdelete_Click" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>
</form>
Namespace
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Data;
C#
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
DataTable dt = new DataTable();
dt.Columns.AddRange(new DataColumn[3] { new DataColumn("Id", typeof(int)),
new DataColumn("Name", typeof(string)),
new DataColumn("Country",typeof(string)) });
dt.Rows.Add(1, "John Hammond", "United States");
dt.Rows.Add(2, "Mudassar Khan", "India");
dt.Rows.Add(3, "Suzanne Mathews", "France");
dt.Rows.Add(4, "Robert Schidner", "Russia");
GridView1.DataSource = dt;
GridView1.DataBind();
}
}
protected void lnkdelete_Click(object sender, EventArgs e)
{
GridViewRow gvrow = (sender as ImageButton).NamingContainer as GridViewRow;
IOrderedDictionary dataKeyNames = GridView1.DataKeys[gvrow.RowIndex].Values;
Dictionary<string, string> dataKeyName = new Dictionary<string, string>();
foreach (DictionaryEntry de in dataKeyNames)
{
dataKeyName.Add(de.Key.ToString(), de.Value.ToString());
}
string id = dataKeyName["Id"].ToString();
string name = dataKeyName["Name"].ToString();
}