I have a grid view with a button field that when clicked I want it to
redirect to another page, passing the primary key of the row with it.
This was a pretty easy thing to do with the DataGrid, but it is so far
proving a pain with the GridView.
Here is my button :
<asp:ButtonField ButtonType="Image" ImageUrl="~/Images/btnDetails.jpg"
CommandName="OpportunityDetails" />
In the GridView DataKeyNames is set like this :
DataKeyNames="OpportunityID"
And I am trying to redirect using this code :
protected void GridView1_RowCommand(object sender,
GridViewCommandEventArgs e)
{
if (e.CommandName == "OpportunityDetails")
{
//get PK (opportunityID)
int intOppID = Convert.ToInt32(e.CommandArgument);
Response.Redirect("OpportunityDetails.aspx?oppid=" +
intOppID);
}
}
Instead of the PrimaryKey being passed, I just get the GridView index
passed (for the first row 0 is passed, for the second row 1 is passed
etc).
There must be a simple solution to this, I'm hoping somebody can tell me
what it is!
*** Sent via Developersdex http://www.developersdex.com ***