if I understood correctly, this should do what you want:
.aspx:
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="id" onselectedindexchanged="GridView1_SelectedIndexChanged">
code behind:
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e) { int index = Convert.ToInt16(GridView1.SelectedDataKey.Value); }
this should do what you want. index.exe will give you the selected row identifier provided by the DataKeyNames attribute on your .aspx page. However, this requires an “Enable selection” check. (Go to the .aspx page, constructor, click on gridview, you will see the "Enable selection" attribute).
source share