Add Custom Control to GridView Column Header

I am trying to add a custom control to the column header in a grid view. I am doing this on RowDataBound, but that might be incorrect. The ultimate goal is to have the Custom Control appear next tot the HeaderText and still allow the HeaderText to sort the columns. Here is my code:

1            If e.Row.RowType = DataControlRowType.Header Then
2                Dim oCell As System.Web.UI.WebControls.TableCell
3                For Each oCell In e.Row.Cells
4                    Dim oHelp As New admin_controls_HelpItem
5                    oHelp.ID = "hlpItem"
6                    oHelp.HelpText = "Help Me"
7                    oCell.Controls.Add(oHelp)
8                Next
9            End If

 

The only problem is that when the page loads the control does not show up.

0
CRLord
12/21/2006 3:35:25 PM
asp.net.presentation-controls 72751 articles. 3 followers. Follow

1 Replies
874 Views

Similar Articles

[PageSpeed] 18

I figured it out. For anyone else trying to do this here is the modified code:

  

1            If e.Row.RowType = DataControlRowType.Header Then
2                Dim oCell As System.Web.UI.WebControls.TableCell
3                For Each oCell In e.Row.Cells
4                    Dim oHelp As admin_controls_HelpItem
5                    oHelp = Page.LoadControl("/admin/controls/HelpItem.ascx")
6                    oHelp.HelpText = HelpSystemDAL.GetHelp("Tax", "Country")
7                    oCell.Controls.Add(oHelp)
8                Next
9            End If

 

Put this inside RowCreated

0
CRLord
12/21/2006 4:41:42 PM
Reply: