Posted on 2007-09-03 14:00
玄铁剑 阅读(856)
评论(1) 编辑 收藏 引用 所属分类:
asp.net
public static void GroupRows(GridView gvMerge, int cellNum)
{
int i = 0, rowSpanNum = 1;
while (i < gvMerge.Rows.Count - 1)
{
GridViewRow gvr = gvMerge.Rows[i];
for (++i; i < gvMerge.Rows.Count; i++)
{
GridViewRow gvrNext = gvMerge.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 == gvMerge.Rows.Count - 1)
{
gvr.Cells[cellNum].RowSpan = rowSpanNum;
}
}
}
}