1 string _tempvalue="";
2 int _temprowspan = 1;
3 TableCell _temptablecell=null;
4
5 protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
6 {
7
8 if (e.Row.RowType == DataControlRowType.DataRow || e.Row.RowType == DataControlRowType.Footer)
9 {
10 if (e.Row.Cells[0].Text == _tempvalue)
11 {
12 _temprowspan++;
13 e.Row.Cells.Remove(e.Row.Cells[0]);
14 }
15 else
16 {
17 if (_temprowspan != 1)
18 _temptablecell.RowSpan = _temprowspan;
19
20 _tempvalue = e.Row.Cells[0].Text;
21 _temptablecell = e.Row.Cells[0];
22 _temprowspan = 1;
23 }
24 }
25 }
在此例中的方法是:若单元格重复,则删除此单元格,并设置未重复的第一个单元格的RowSpan为跨度包含的重复数。