码迷,mamicode.com
首页 > 其他好文 > 详细

GridView如何合并同类项

时间:2015-06-16 12:59:06      阅读:90      评论:0      收藏:0      [点我收藏+]

标签:

 /// <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;
                }
            }
        }
    }

GridView如何合并同类项

标签:

原文地址:http://www.cnblogs.com/LoveQin/p/4580394.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!