I have a gridview that shows information from a SqlDatasource. Now the gridview shows some information with an edit button and a delete button at the end of the row.
I want to retrieve the primary key of that row from a table in C#, when I click on the edit or the delete button.
For this I overriden two functions:
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
Response.Write(e.NewEditIndex);
}
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
Response.Write(SqlDataSource1.DeleteCommand);
}
But I cannot retrieve the primary key value. How can I do that?
GridView uses
DataKeyNamesproperty, which a collection of key fields. You may useGridView1.DataKeysproperty to retrieveKeyFieldvalue.