Don't use commandName(Delete it) if you want defined your own, example set "DataKeyNames" for fields "SN" and "Sex" (depend what field value you want to take),
<asp:GridView ID="GridView1" runat="server" DataKeyNames="SN,Sex" AllowPaging="True" Height="326px" OnPageIndexChanging="GridView1_PageIndexChanging" >
<asp:TemplateField>
<ItemTemplate>
<asp:Button ID="TestClick" Text="Test" runat="server" OnClick="Unnamed_Click" />
</ItemTemplate>
</asp:TemplateField>
</asp:GridView>
Code Behind:
protected void Unnamed_Click(object sender, EventArgs e)
{
try
{
Button TestClick = sender as Button;
GridViewRow rowlist = TestClick.NamingContainer as GridViewRow;
var rowindex = rowlist.RowIndex;
var SNField = this.GridView1.DataKeys[rowindex]["SN"].ToString();
var SexField = this.GridView1.DataKeys[rowindex]
["Sex"].ToString();
}
catch (Exception ex)
{
}
}