Gridview控件合并tr和td显示数据解决方法
通过gridview控件和代码的控制解决,代码如下
//合并tr显示数据
private static void GroupRows(GridView GridView1, int cellNum, int begin, int end)
{
int i = begin, rowSpanNum = 1;
while (i < end)
{
GridViewRow gvr = GridView1.Rows[i];
for (++i; i < end; i++)
{
GridViewRow gvrNext = GridView1.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 == GridView1.Rows.Count - 1)
{
gvr.Cells[cellNum].RowSpan = rowSpanNum;
}
}
}
}
在方法中如下调用
GroupRows(Smalltype, 0, 0, Smallgoodstype.Count);
第一个0表示第几列,第二个0表示开始的行数