/// <summary>
/// 从第二行开始,比较本行和上行的单元格,相同则合并
/// </summary>
/// <param name="gv">GridView</param>
/// <param name="colIndex">合并列的序号</param>
public static void GroupCol(GridView gv, int colIndex)
{
if (gv.Rows.Count < 1)
{
return;
}
//从第二行开始,比较本行和上行的单元格,相同则合并
TableRow oldTr = gv.Rows[0];
int preIndex;
//if (colIndex == 2)
//{
// preIndex = 1;
//}
//else
//{
preIndex = colIndex;
//}
TableRow tr;
for (int i = 1; i < gv.Rows.Count; i++)
{
tr = gv.Rows[i];
if (oldTr.Cells[colIndex].Text == tr.Cells[colIndex].Text && oldTr.Cells[preIndex].Text == tr.Cells[preIndex].Text)
{
tr.Cells[colIndex].Visible = false;
if (oldTr.Cells[colIndex].RowSpan == 0)
{
oldTr.Cells[colIndex].RowSpan = 1;
}
oldTr.Cells[colIndex].RowSpan++;
oldTr.VerticalAlign = VerticalAlign.Middle;
}
else
{
oldTr = tr;
}
}
}