根据主键,合并gridview的行_[Asp.Net教程]
///
要合并行的gridview
///
要合并行的列集合
///
合并所依据的主键
public static void GroupRows(GridView GridView1, int[] cellNums, string keyname)
{
int i = 0, rowSpanNum = 1;
while (i
{
GridViewRow gvr = GridView1.Rows[i];
for (++i; i < GridView1.Rows.Count; i++)
{
GridViewRow gvrNext = GridView1.Rows[i];
if (GridView1.DataKeys[i - 1][keyname].ToString() == GridView1.DataKeys[i][keyname].ToString())
{
for (int s = 0; s < cellNums.Length; s++)
{
gvrNext.Cells[cellNums[s]].Visible = false;
}
rowSpanNum++;
}
else
{
for (int s = 0; s < cellNums.Length; s++)
{
gvr.Cells[cellNums[s]].RowSpan = rowSpanNum;
}
rowSpanNum = 1;
break;
}
if (i == GridView1.Rows.Count - 1)
{
for (int s = 0; s < cellNums.Length; s++)
{
gvr.Cells[cellNums[s]].RowSpan = rowSpanNum;
}
}
}
}
}