I am trying to add a "super header" row to my gridview. It seems I can only do this in codebehind. In the header, I want to add a textbox and attach a textchange event handler. But, while the code generates the header row and textbox, it does not seem to attached the event handler. Here is my code:
Protected Sub GridViewBegroting_DataBound(ByVal sender As Object, ByVal e As EventArgs) Handles testGrid.DataBound
Dim myGridView As GridView = sender
If myGridView.Controls.Count > 0 Then
AddSuperHeader(myGridView)
End If
End Sub
Protected Sub AddSuperHeader(ByVal gridView As GridView)
Dim myTable As Table = gridView.Controls(0)
Dim cell As TableHeaderCell = MakeCell("Search", 4)
Dim tb As HtmlGenericControl = MakeTextBox()
Dim myNewRow As GridViewRow = New GridViewRow(0, -1, DataControlRowType.Header, DataControlRowState.Normal)
cell.Controls.Add(tb)
myNewRow.Cells.Add(cell)
myTable.Rows.AddAt(0, myNewRow)
End Sub
Protected Function MakeTextBox() As HtmlGenericControl
Dim div1 As HtmlGenericControl = New HtmlGenericControl("div")
Dim span1 As HtmlGenericControl = New HtmlGenericControl("span")
Dim tb As TextBox = New TextBox
AddHandler tb.TextChanged, AddressOf TestGridView_Search
tb.ID = "testSearchTextBox"
tb.Attributes("placeholder") = "Search Term"
div1.Controls.Add(span1)
div1.Controls.Add(tb)
Return div1
End Function
Protected Function MakeCell(Optional ByVal text As String = "", Optional ByVal span As Int32 = 1) As TableHeaderCell
Dim header As New TableHeaderCell()
header.ColumnSpan = span
header.Text = text
header.CssClass = "table-header"
Return (header)
End Function
Protected Sub TestGridView_Search(ByVal sender As Object, ByVal e As EventArgs)
Dim i As Integer = 0
End Sub
This creates all the correct controls, but the event does not fire. There are no errors but the break point on TestGridView_Search does not fire. Also, this is a user control (ASCX). I have tried doing this by attaching a javascript ajax function, but that does not seem to work in ASCX files.