I have a working solution to repeat DataGrid Headers every X rows, but the approach I took only works if there's a single DataGrid that needs repeated headers.
Can anyone think of a way to tweak this so that I might be able to use it on any page, regardless of the number of DataGrids that would need this functionality?
Can anyone think of a way to tweak this so that I might be able to use it on any page, regardless of the number of DataGrids that would need this functionality?
Code:
Namespace SummaryReport
Partial Class _CostDetails
Dim intDGRowCounter As Integer = 0
Dim ListOfHeaderFields As New ArrayList()
Dim RowInterval As Integer = 12
[............................................]
Protected Sub dgCostBreakdown_ItemCreated(ByVal sender As Object, ByVal e As DataGridItemEventArgs) Handles dgCostBreakdown.ItemCreated
Dim dgItem As DataGridItem
If (e.Item.ItemType = ListItemType.Header) Then
Dim i As Integer = 0
For i = 0 To e.Item.Cells.Count - 1
ListOfHeaderFields.Add(e.Item.Cells(i).Text)
Next
End If
If ((e.Item.ItemType = ListItemType.Item) Or (e.Item.ItemType = ListItemType.AlternatingItem)) Then
intDGRowCounter = intDGRowCounter + 1
If (intDGRowCounter Mod (RowInterval + 1) = 0) Then
Dim j As Integer = 0
Dim HeaderCells(ListOfHeaderFields.Count) As TableCell
dgItem = New DataGridItem(0, 0, ListItemType.Header)
For j = 0 To ListOfHeaderFields.Count - 1
Dim aCell As New TableCell()
aCell.Text = ListOfHeaderFields.Item(j).ToString()
dgItem.Cells.Add(aCell)
Next
dgCostBreakdown.Controls(0).Controls.AddAt(intDGRowCounter, dgItem)
End If
End If
End Sub