zoukankan      html  css  js  c++  java
  • 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;
                        gvrNext.Cells[cellNum + 1].Visible = false;//合并第二列
                        rowSpanNum++;
                    }
                    else
                    {
                        gvr.Cells[cellNum].RowSpan = rowSpanNum;
                        gvr.Cells[cellNum + 1].RowSpan = rowSpanNum;//合并第二列
                        rowSpanNum = 1;
                        break;
                    }
                    if (i == GridView1.Rows.Count - 1)
                    {
                        gvr.Cells[cellNum].RowSpan = rowSpanNum;
                        gvr.Cells[cellNum + 1].RowSpan = rowSpanNum;//合并第二列
                    }
                }
            }
        }

    根据第一列具有相同的行合并第一,二列具有相同的行。

  • 相关阅读:
    8-JS闭包、回调实例
    7-闭包、回调
    6-JS函数(二)
    5-JS函数
    4-JS对象
    3-WebPack
    2-Babel
    1-NPM
    25-React事件处理及条件渲染
    java初始化笔记
  • 原文地址:https://www.cnblogs.com/jonson1126/p/3152573.html
Copyright © 2011-2022 走看看