Robert Van Hoose
Robert Van Hoose

Reputation: 203

GridView Row styles and attributes not rendered

I am trying to add a style and add row behavior to my GridView in the OnRowDataBound event (change the cursor and add onmouseover and onmouseout to highlight a row). When I use an HtmlTextWriter to show the markup of the row within that method everything looks fine. However, in the page source on the browser side, my <tr> elements simply don't have the attributes at all. If I dump the markup in the OnPreRender or OnPreRender complete events of the page, I find that my changes have disappeared by that point. What's going on here?

I am using VS2010 Professional and targeting the 3.5 framework.

UPDATE: I tried some different things to determine where things are going wrong. I subclassed both GridView and GridViewRow so that I could get in front of some of the method calls to determine when my settings get blasted. It turned out to be in GridView.RenderControls() that my attributes were dropped. I don't understand this as there are dozens of examples (including on this site) of adding javascript events using this technique. I ended up having success by overriding the RenderControl() method in my subclass and using it to call base.Render() rather than base.RenderControl()... strange but true.

Upvotes: 1

Views: 430

Answers (1)

Robert Van Hoose
Robert Van Hoose

Reputation: 203

I ended up having success by subclassing GridView and then overriding the RenderControl() method in my subclass and using it to call base.Render() rather than base.RenderControl()... strange but true.

Upvotes: 1

Related Questions