|


解決方法如下(寫在公共模塊里,定義為靜態方法方便調用):
復制代碼 代碼如下:
/// <summary>
/// 合并GridView中某列相同信息的行(單元格)
/// </summary>
/// <param name="GridView1">GridView</param>
/// <param name="cellNum">第幾列</param>
public static void GroupRows(GridView GridView1, int cellNum)
{
int i = 0, rowSpanNum = 1;
while (i < GridView1.Rows.Count - 1)
{
GridViewRow gvr = GridView1.Rows[i];
for (++i; i < GridView1.Rows.Count; 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;
}
}
}
}
如果多列要求合并時,可作適當修改。
一個完整的人生應該是寬恕、容忍、等待和愛!
AspNet技術:asp.net 合并GridView中某列相同信息的行(單元格),轉載需保留來源!
鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯系我們修改或刪除,多謝。