Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Repeat DataGrid Headers every X rows (help)

Status
Not open for further replies.

roleki

Technical User
Sep 5, 2007
22
US
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?

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


 
I would preform the html manipulation using the client script rather than server code. jquery can make this really simple and can account for any number of tables.

this way you do not need to pollute the code behind with presentation concerns.

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top