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为跨度包含的重复数。
本文介绍了一种在ASP.NET GridView控件中优化RowSpan属性的方法,通过该方法可以实现在数据行或页脚中合并相同值的单元格,并设置首个单元格的RowSpan属性来反映合并的行数。
274

被折叠的 条评论
为什么被折叠?



