Say I have only two columns in my GridView (ID & Name) and I need to get the value of ID whenever I click on it. For example, if I click on 123, I should get 123. But here... that's not the case... when I click on any ID it returns the name beside that ID right (eg; in case of 123, I get Tony Stark), but when I get the value of ID on click, it always returns me an empty string.
In other words, I get the name in id right (when X=1), but when X=0, id becomes an empty string... (int X and string id : see C# code below)
XAML Code in my GridView:
<asp:ButtonField
DataTextField="ID"
HeaderText="ID">
</asp:ButtonField>
<asp:BoundField
DataField="Name"
HeaderText="NAME">
</asp:BoundField>
C#:
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
string id = GridView1.Rows[Convert.ToInt32(e.CommandArgument)].Cells[X].Text.ToString();
Response.Write(id);
}
What's going wrong?!! And how to fix this? Thanks!