zoukankan      html  css  js  c++  java
  • 对gridview的小改动

    ///


        /// 合并某列内容相同的行
        ///

        ///
        ///
        public static void GroupRows(GridView GridView1, int cellNum)
        {
            int i = 0;
            int 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;
                    }
                }
            }
        }

    protected void gvMain_DataBound(object sender, EventArgs e)
        {
            GroupRows(this.gvMain, 1);

        }

    //加合计行

    protected void gvMain_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType != DataControlRowType.Footer && e.Row.RowType != DataControlRowType.Header)
            {
                DataRowView drv = (DataRowView)e.Row.DataItem;

                iNumber = Convert.ToInt32(drv[4]);
                totalNumber += iNumber;
            }
            if (e.Row.RowType == DataControlRowType.Footer) 
            {
                e.Row.Cells[4].Text = string.Format("{0}", totalNumber);
                e.Row.Cells[1].Text = "合计";
                e.Row.Cells[3].Visible = false;
                e.Row.Cells[1].ColumnSpan = 2;
                e.Row.Height = 32;
            }
        }

    欢迎拍砖,欢迎转载,欢迎关注,欢迎联系,就是各种欢迎
  • 相关阅读:
    常见 Web 安全攻防总结
    传统方式接口测试返回值json验证
    Springboot中RestTemplate -- 用更优雅的方式发HTTP请求
    mock简单的json返回
    MySQL数据库学习笔记(五)----MySQL字符串函数、日期时间函数
    MySQL数据库学习笔记(四)----MySQL聚合函数、控制流程函数(含navicat软件的介绍)
    MySQL数据库学习笔记(三)----基本的SQL语句
    MySQL数据库学习笔记(一)----MySQL 5.6.21的安装和配置(setup版)
    python实现广度优先搜索
    php递归
  • 原文地址:https://www.cnblogs.com/EddyPeng/p/1225883.html
Copyright © 2011-2022 走看看