BoundField绑定列的合并
/// <summary>
/// 合并BoundField绑定列
/// </summary>
/// <param name="gv">需要合并GridView</param>
/// <param name="cellNum">第几列</param>
public void GroupRows(GridView gv, int cellNum)
{
int i = 0, rowSpanNum = 1;
while (i < gv.Rows.Count - 1)
{
GridViewRow gvr = gv.Rows[i];
for (++i; i < gv.Rows.Count; i++)
{
GridViewRow gvrNext = gv.Rows[i];
if (gvr.Cells[cellNum].Text == gvrNext.Cells[cellNum].Text)
{
gvrNext.Cells[cellNum].Visible = false;
rowSpanNum++;
}
else
{
gvr.Cells[cellNum].RowSpan = rowSpanNum;
rowSpanNum = 1;
break;
}
if (i == gv.Rows.Count - 1)
{
gvr.Cells[cellNum].RowSpan = rowSpanNum;
}
}
}
}