富贵资源网 Design By www.hznty.com
asp.net 合并GridView中某列相同信息的行(单元格)                                      asp.net 合并GridView中某列相同信息的行(单元格)  
解决方法如下(写在公共模块里,定义为静态方法方便调用):
复制代码 代码如下:
/// <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;
}
}
}
}


如果多列要求合并时,可作适当修改。
一个完整的人生应该是宽恕、容忍、等待和爱!
富贵资源网 Design By www.hznty.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
富贵资源网 Design By www.hznty.com