Wednesday, December 26, 2012

Merge Particular column that is repeating in Gridview

Protected Sub GridView1_RowDataBound(sender As Object, e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound

     
        For rowIndex As Integer = GridView1.Rows.Count - 2 To 0 Step -1
            Dim gviewRow As GridViewRow = GridView1.Rows(rowIndex)
            Dim gviewPreviousRow As GridViewRow = GridView1.Rows(rowIndex + 1)
            Dim cellCount As Integer = 0//replace 0 with column index
            If gviewRow.Cells(cellCount).Text = gviewPreviousRow.Cells(cellCount).Text Then
                If gviewPreviousRow.Cells(cellCount).RowSpan < 2 Then
                    gviewRow.Cells(cellCount).RowSpan = 2
                Else
                    gviewRow.Cells(cellCount).RowSpan = gviewPreviousRow.Cells(cellCount).RowSpan + 1
                End If
                gviewPreviousRow.Cells(cellCount).Visible = False
            End If
        Next



    End Sub

No comments :

Post a Comment