User839733648 posted
Hi JagjitSingh ,
I suggest you could use Datakeys to find the value.
You should first set the DataKeyNames in the GridView.
Then you may get the value you want in the GridView1_RowCommand event using the following statement.
int rowIndex = Convert.ToInt32(e.CommandArgument);
string value = GridView1.DataKeys[rowIndex].Values["BoundfieldName"].ToString();
For more details, you could refer to the code below.
.aspx
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" OnRowCommand="GridView1_RowCommand"
DataKeyNames="Eid,Ename">
<Columns>
<asp:BoundField DataField="Eid" HeaderText="Eid" SortExpression="Eid" />
<asp:BoundField DataField="Ename" HeaderText="Ename" SortExpression="Ename" />
<asp:BoundField DataField="age" HeaderText="age" SortExpression="age" />
<asp:BoundField DataField="sex" HeaderText="sex" SortExpression="sex" />
<asp:CommandField HeaderText="Operation" ShowDeleteButton="True" ShowEditButton="True"/>
</Columns>
</asp:GridView>
code behind.
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
int rowIndex = Convert.ToInt32(e.CommandArgument);
string EidTxt = GridView1.DataKeys[rowIndex].Values["Eid"].ToString();
string EnameTxt = GridView1.DataKeys[rowIndex].Values["Ename"].ToString();
}
result(when clicking the row where Eid=7 ):



Best regards,
Jenifer