GridView中数据相同的单元格合并
阅读(39) 评论(0) 发表时间:2008年05月26日 09:18
这是一个方法,直接调用,参数1:GridView控件,参数2:要合并的列
public static void GroupRows(GridView gvMerge, int cellNum)
{
int i = 0, rowSpanNum = 1;
while (i < gvMerge.Rows.Count - 1)
{
GridViewRow gvr = gvMerge.Rows ;
for (++i; i < gvMerge.Rows.Count; i++)
{
GridViewRow gvrNext = gvMerge.Rows;
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;
}
}
}
}
public static void GroupRows(GridView gvMerge, int cellNum)
{
int i = 0, rowSpanNum = 1;
while (i < gvMerge.Rows.Count - 1)
{
GridViewRow gvr = gvMerge.Rows ;
for (++i; i < gvMerge.Rows.Count; i++)
{
GridViewRow gvrNext = gvMerge.Rows;
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;
}
}
}
}