Code Simplified – Viral Sarvaiya

Code Simplified – Viral Sarvaiya, Web Developer Friends, dot net Developer, Sql Server Developer

Posts Tagged ‘How To merging Cell in Gridview’

ASP.NET Gridview: Merging Cells

Posted by Viral Sarvaiya on November 4, 2009


I had been searching for a way to merge cells in a GridView


If e.Row.DataItemIndex % 2 = 0 Then
e.Row.Cells(0).RowSpan = 2
e.Row.Cells(1).RowSpan = 2
End If
'Remove the extra cells created due to row span for odd rows
If e.Row.DataItemIndex % 2 = 1 Then
e.Row.Cells.RemoveAt(0)
e.Row.Cells.RemoveAt(0)
e.Row.Cells(1).HorizontalAlign = HorizontalAlign.Center
End If

This code should take every cell in the first and second columns and merge it with the cell directly below it. Of course, this should be used very carefully, because you could screw up your data if each record does not have another corresponding record with it. However, this shouldn’t be too difficult to program around by adding data checks.

Posted in ASP.NET | Tagged: , , | Leave a Comment »

 
Follow

Get every new post delivered to your Inbox.

Join 44 other followers

%d bloggers like this: