>I have a WebForm which has upon it a GridView. Defined in the GridView header template is an Asp control. I need to reference that control in the Code-Behind but there seems to be no way to get to it. Is there any way to access this object besides Me.GridView1.HeaderRow.FindControl("BtnSortBy")? And if so how do I construct an event handler for it?
>
>Thanks
>
>Glenn
I have not jumped in the VS 2005 "bandwagon" yet but this is how you can do it in VS 2003:
1) For finding a control without using FindControl you can loop through the Controls collection of the container object. Not pretty, but you can do it..
For Each ctl In Me.GridView1.HeaderRow
If ctl.HasControls Then ..
.. then compare the ID of the controls to the one you are trying to find. (I said it wasn't pretty)
2) To associate an event handler you can use AddHandler:
AddHandler myBtn.PreRender, AddressOf myBtn_PreRender
Where myBtn_PreRender is a Sub that you provide, preferably with the same signature as you would get if VS creates the handler for you. (as when you dbl-click on the aspx surface to get your Page_Load)
I hear the GridView is soo much better than the regular DataGrid in 2003, I sure hope so. I had to jump through hoops to customize this control on a recent project.. HTH