Wednesday, September 15, 2010

Merging cells in a gridview

This post http://jingyang.spaces.live.com/blog/cns!CC21A118B1B5250!192.entry showed me how to merge cells in a gridview (I was principally interested in the footer row).

Say you want to merge cells three and four of a ten column row, you'd start by getting rid of cell four and then setting the ColumnSpan property of cell three to be two. Note the index is zero-based.

Gridview1.FooterRow.Cells.RemoveAt(3)
Gridview1.FooterRow.Cells(2).ColumnSpan=2

Straight forward. What it took me a while to work out is that now you only have a nine column row, so if you wanted to then go on and span across what were originally columns six and seven you actually have to do:

Gridview1.FooterRow.Cells.RemoveAt(5)
Gridview1.FooterRow.Cells(4).ColumnSpan=2

I found I was writing code that appeared to be removing the same column twice!

Labels:

0 Comments:

Post a Comment

<< Home