Protected Sub OnDataBound(sender As Object, e As EventArgs)
For i As Integer = Empdata.Rows.Count - 1 To 1 Step -1
Dim row As GridViewRow = Empdata.Rows(i)
Dim previousRow As GridViewRow = Empdata.Rows(i - 1)
For j As Integer = 0 To row.Cells.Count - 2
'run this loop for the column which you thing the data will be similar
If DirectCast(row.Cells(j).FindControl("lblDesignation"), Label).Text = DirectCast(previousRow.Cells(j).FindControl("lblDesignation"), Label).Text Then
If previousRow.Cells(2).RowSpan = 0 Then
If row.Cells(2).RowSpan = 0 Then
previousRow.Cells(2).RowSpan += 2
Else
previousRow.Cells(2).RowSpan = row.Cells(2).RowSpan + 1
End If
row.Cells(2).Visible = False
End If
End If
'run this loop for the column which you thing the data will be similar
If DirectCast(row.Cells(j).FindControl("lblDepartment"), Label).Text = DirectCast(previousRow.Cells(j).FindControl("lblDepartment"), Label).Text Then
If previousRow.Cells(5).RowSpan = 0 Then
If row.Cells(5).RowSpan = 0 Then
previousRow.Cells(5).RowSpan += 2
Else
previousRow.Cells(5).RowSpan = row.Cells(5).RowSpan + 1
End If
row.Cells(5).Visible = False
End If
End If
Next
Next
End Sub