asp.net中,grideview中显示数据库中的多条数据,怎么样将某一列合并?
展开全部
/// <summary>
/// 合并GridView中某列相同信息的行(单元格)
/// </summary>
/// <param name="GridView1"></param>
/// <param name="cellNum"></param>
public static void GroupCol(GridView gridView, int cols)
{
if (gridView.Rows.Count < 1 || cols > gridView.Rows[0].Cells.Count - 1)
{
return;
}
TableCell oldTc = gridView.Rows[0].Cells[cols];
for (int i = 1; i < gridView.Rows.Count; i++)
{
TableCell tc = gridView.Rows[i].Cells[cols];
if (oldTc.Text == tc.Text)
{
tc.Visible = false;
if (oldTc.RowSpan == 0)
{
oldTc.RowSpan = 1;
}
oldTc.RowSpan++;
oldTc.VerticalAlign = VerticalAlign.Middle;
}
else
{
oldTc = tc;
}
}
}
/// 合并GridView中某列相同信息的行(单元格)
/// </summary>
/// <param name="GridView1"></param>
/// <param name="cellNum"></param>
public static void GroupCol(GridView gridView, int cols)
{
if (gridView.Rows.Count < 1 || cols > gridView.Rows[0].Cells.Count - 1)
{
return;
}
TableCell oldTc = gridView.Rows[0].Cells[cols];
for (int i = 1; i < gridView.Rows.Count; i++)
{
TableCell tc = gridView.Rows[i].Cells[cols];
if (oldTc.Text == tc.Text)
{
tc.Visible = false;
if (oldTc.RowSpan == 0)
{
oldTc.RowSpan = 1;
}
oldTc.RowSpan++;
oldTc.VerticalAlign = VerticalAlign.Middle;
}
else
{
oldTc = tc;
}
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询