protected void gv_DataBound(object sender, EventArgs e)
{
for (int row = 0; row < gv.Rows.Count; row++)
{
for (int col = 0; col < gv.Rows[row].Cells.Count; col++)
{ int cut1 = 1;
while
(
cut1 + row < gv.Rows.Count && gv.Rows[row].Cells[col].Text == gv.Rows[cut1 + row].Cells[col].Text
)
++cut1;
gv.Rows[row].Cells[col].RowSpan = cut1;
for (; cut1 > 1; cut1--)
{
if (cut1 + row <= gv.Rows.Count)
{
gv.Rows[row + cut1 - 1].Cells[col].Visible = false;
}
}
}
}
}
本文介绍了一种在ASP.NET中使用GridView控件时合并重复单元格的方法。通过遍历GridView的每一行和每一列,比较相邻行的相同列内容是否一致来实现合并,提升了表格的显示效果。

1439

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



