Reputation: 3839
I want a row in an ASP.NET GridView
to be selected with specified value for SelectedValue
.
The DataKeyNames
in GridView
is SN
, and I have something like this:
mySN = 5;
I want to find the row in GridView
its value is equal to mySN
with C#
code.
Upvotes: 1
Views: 1824
Reputation: 172438
Try this:-
<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);
}
Upvotes: 1