gridview合并单元格
来源:互联网 发布:数据库缺省值怎么设置 编辑:程序博客网 时间:2024/04/26 23:07
效果如图 代码如下。
private void RowSpan() { int n, m ,j; for (int i = 0; i < GridView1.Rows.Count; i++) { n = 1; for (j = i + 1; j < GridView1.Rows.Count; j++) { if (GridView1.Rows[i].Cells[0].Text.Trim() == GridView1.Rows[j].Cells[0].Text.Trim()) { n += 1; GridView1.Rows[i].Cells[0].RowSpan = n; GridView1.Rows[j].Cells[0].Visible = false; } else break; } i = j - 1; } for (int i = 0; i < GridView1.Rows.Count; i++) { m = 1; for (j = i + 1; j < GridView1.Rows.Count; j++) { if (GridView1.Rows[i].Cells[1].Text.Trim() == GridView1.Rows[j].Cells[1].Text.Trim()) { m += 1; GridView1.Rows[i].Cells[1].RowSpan = m; GridView1.Rows[j].Cells[1].Visible = false; } else break; } i = j - 1; } }