Skip to content

Instantly share code, notes, and snippets.

@rbipin
Last active March 23, 2018 19:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rbipin/b2b76428f9028c251d26696ee2dc360a to your computer and use it in GitHub Desktop.
Save rbipin/b2b76428f9028c251d26696ee2dc360a to your computer and use it in GitHub Desktop.
Aspx Gridview with a main header and subheader
''' <summary>
''' Create a Subheader above the actual grid header
''' </summary>
''' <param name="sender"></param>
''' <param name="e"></param>
Protected Sub DataGrid_RowCreated(sender As Object, e As UI.WebControls.GridViewRowEventArgs) Handles datagrid.RowCreated
Dim datagrid As GridView = Nothing
Dim headercell As TableHeaderCell = Nothing
Dim gridsubheaderrow As GridViewRow = Nothing
Dim gridFooterCell As TableCell = Nothing
Try
datagrid = CType(sender, GridView)
If (e.Row.RowType = DataControlRowType.Header) Then
gridsubheaderrow = New GridViewRow(0, 0, DataControlRowType.Header, DataControlRowState.Insert)
headercell = New TableHeaderCell()
headercell.Text = ""
gridsubheaderrow.Cells.Add(headercell)
headercell = New TableHeaderCell()
headercell.Text = "Cash"
headercell.ColumnSpan = 3
gridsubheaderrow.Cells.Add(headercell)
headercell = New TableHeaderCell()
headercell.Text = "Check"
headercell.ColumnSpan = 3
gridsubheaderrow.Cells.Add(headercell)
headercell = New TableHeaderCell()
headercell.Text = ""
gridsubheaderrow.Cells.Add(headercell)
datagrid.Controls(0).Controls.AddAt(0, gridsubheaderrow)
End If
Catch ex As Exception
Throw
End Try
End Sub
@rbipin
Copy link
Author

rbipin commented Mar 23, 2018

About the Snippet

This is the code snippet to create a custom header above the default aspxGridview column header. The details and the sample screenshot of the gridview is given in the blog post

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment