I'm using the code found here to make my gridview have clickable rows. The code for that is:
protected void gvdownloadaccounts_RowDataBound(object sender, GridViewRowEventArgs e)
{
e.Row.Cells[0].Visible = false; //hide the ID
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes["onmouseover"] = "this.style.cursor='pointer';this.style.textDecoration='underline';";
e.Row.Attributes["onmouseout"] = "this.style.textDecoration='none';";
e.Row.ToolTip = "Click to select row";
e.Row.Attributes["onclick"] = this.Page.ClientScript.GetPostBackClientHyperlink(this.gvdownloadaccounts, "Select$" + e.Row.RowIndex);
}
}
...which works great!...except that I need to make it so that the "onclick" runs a C# method in the code behind. That method gets data from the database and fills in some web controls (like textboxes, etc.) with that data. This doesn't seem like it should be that hard, so if someone could just give me a kick in the right direction, that'd be awesome.
I was toying with the idea of just re-directing to the same page, but with a query string, that way I could catch my code on page_load. But as one might expect:
e.Row.Attributes["onclick"] = Response.Redirect("www.google.com");
...doesn't work.