Last post Feb 22, 2007 06:33 PM by Puhfista
Feb 21, 2007 12:50 PM|Puhfista|LINK
I have several Gridviews in a web application, most of which had the following Event Handler for OnRowDataBound
protected void GridViewClickAbility(object sender, GridViewRowEventArgs e)
string test = sender.ToString();
if (e.Row.RowType == DataControlRowType.DataRow)
e.Row.Attributes["onmouseover"] = "this.style.cursor='hand';";
ClientScript.GetPostBackClientHyperlink((GridView)sender, "Select$" + e.Row.RowIndex);
What this function does is make it so you and click anywhere in the gridview to cause the "Select" command to run (not just the "SELECT" text/button). I needed to switch the way my Gridview was rendered, so I made all my Gridviews CSS Friendly with the adapters.
However, now my Gridview click ability event handler doesn't work anymore. I did a debug, and the event hanlder code runs on the data bound event, but there are no attributes being added to the gridview row (I checked the source code of the rendered page).
I am really confused.
Does anyone know what is going on?
Feb 22, 2007 02:13 PM|Russ Helfand|LINK
Please look at lines 165 to 171 in App_Code\Adapters\GridViewAdapter.cs,
If you want to add arbitrary attributes to the <tr> of your GridView then you need to uncomment out the code that I put in there. This was left commented out in the "official" version of the adapter because I didn't want to risk having unnecessary attributes
(added potentially by the lower-level ASP.NET framework sitting under the adapters) to the rows. However, I did recognize that sometimes folks need to add their own attributes to the row... so I left this hook (commented out) in the code.
Please let me know if this does (or doesn't) work for your case. Thanks and good luck.
Feb 22, 2007 06:33 PM|Puhfista|LINK