GridView Edit..
-
I need several buttons on each GridView row that redirect to pages performing custom operations. How do I get the DataKey of the row the button was clicked on? So that I can send the database ID of the row I want to perform operations on to another page. I can't use GridView.SelectedDataKey.Value because i'm not always going to be clicking the select button. Nor can I use the index, because that is not the ID for the data in the database.
-
I need several buttons on each GridView row that redirect to pages performing custom operations. How do I get the DataKey of the row the button was clicked on? So that I can send the database ID of the row I want to perform operations on to another page. I can't use GridView.SelectedDataKey.Value because i'm not always going to be clicking the select button. Nor can I use the index, because that is not the ID for the data in the database.
Nevermind. :) This is how I did it. If someone knows a better way, lemme know. I created a button commandField with command "EditRow" and hooked up the RowCommand event.
protected void MainGrid_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName == "EditRow") { DataKey mykey = MainGrid.DataKeys[Convert.ToInt32(e.CommandArgument)]; String mystring = Convert.ToString(mykey.Value); Page.Response.Redirect("Insert.aspx?key=" + mystring); } }