Created
March 12, 2024 19:29
-
-
Save abraxas86/a255761e9796fdf99f625f1f26c0538a to your computer and use it in GitHub Desktop.
VB.NET codebehind to fix GridView Tables so the header row is in a proper <thead> section instead of <tbody>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Public Class GvHelpers | |
''' <summary> | |
''' ASP automatically throws <th> cells in a <tbody> grouping making it tricky to target specific areas of tables | |
''' with CSS and Javascript. This method is used to break the first row of the provded gridview into a proper <thead> section. | |
''' It is recommended that you call this method on RowCreated to ensure the header is kept separate as the user modifies/browses the table, | |
''' otherwise things like flipping between pages would cause the header to get sandwiched back in a <tbody> grouping. | |
''' </summary> | |
''' <param name="gridView">The gridview to separate the header from</param> | |
''' <remarks> | |
''' Example: | |
''' Let's target a gridview defined as "gvMyGridview": | |
''' <code> | |
''' Protected Sub gvMyGridview_RowCreated(ByVal sender As Object, ByVal e As GridViewRowEventArgs) Handles gvMyGridview.RowCreated | |
''' separateGvHeader(gvMyGridview) | |
''' End Sub | |
''' </code> | |
''' </remarks> | |
Public Shared Sub separateGvHeader(ByVal gridView As GridView) | |
If gridView.Rows.Count > 0 AndAlso gridView.HeaderRow IsNot Nothing Then | |
gridView.UseAccessibleHeader = True | |
gridView.HeaderRow.TableSection = TableRowSection.TableHeader | |
End If | |
End Sub | |
End Class |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I know I pluralized the class... I was thinking ahead to if I had any other tools I'd need to add.