When I click on a row in my GridView, I want to go to a other page with the ID I get from the database.
In my RowCreated event I have the following line:
Can your ID be related to the data item displayed in the gridview?
If so you can use e.Row.DataItem, and cast it to whatever type it is.
protected void gvSearch_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
GridViewRow gvr = e.Row;
string abc = ((GridView)sender).DataKeys[e.Row.RowIndex].Value.ToString();
gvr.Attributes.Add("OnClick", "javascript:location.href='Default.aspx?id=" + abc + "'");
}
}
}
You can use the RowCommand event of the grid view for it. In your button/link where you wnat to set the click on, set the CommandName and CommandArgument, which you can accees at the EventArgs paramter of the event method.