On Button1_Click need to get value from selected DataKey (User presses Select in gridview and highlights row)
This is k开发者_开发问答iling me. On Button1_Click I need to get the value from selected DataKey (User presses Select in gridview and highlights row)..Can anyone help? Thank You..
protected void Button1_Click(object sender, EventArgs e)
{
string id = GridView1.SelectedDataKey.Value.ToString();
Label1.Text = id;
}
You haven't mentioned what's not working, do you get any errors?
To retrieve the SelectedDataKey you have to tell the GridView what's the primary key column of your datasource via it's property DataKeyNames. You could also use the GridView's SelectedValue property.
If all does not work, you should provide source code. Maybe you are binding the GridView on every postback.
精彩评论