zoukankan      html  css  js  c++  java
  • 统计合并griview2

      注:将ShowFooter属性设置为true

           int mysum1 = 0;
            Double mysum2 = 0;
            protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
            {
                if (e.Row.RowType == DataControlRowType.DataRow)
                {
                    DataRowView myrows = (DataRowView)e.Row.DataItem;

                      //要统计总数的列
                    mysum1 += Convert.ToInt32(myrows[8].ToString());
                    mysum2 += Convert.ToDouble(myrows[9].ToString());
                }
                // 合计
                //if (e.Row.RowType == DataControlRowType.Footer)
                //{
                //    e.Row.Cells[0].Text = "合计";
                //    e.Row.Cells[8].Text = "总本数:" + mysum1.ToString();
                //    e.Row.Cells[9].Text =mysum2.ToString();
                //}
            }

          //合并单元格

            protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
            {

              //判断是否是表脚
                if (e.Row.RowType == DataControlRowType.Footer)
                {

                    //获取表脚所在的所有单元格
                    TableCellCollection TableCell = e.Row.Cells;

                  //自动清除表脚
                    TableCell.Clear();
                    TableCell.Add( new TableHeaderCell() );
                    TableCell[0].Text = "合计:";

                    TableCell.Add(new TableHeaderCell());
                    TableCell[1].ColumnSpan =8;                          //合并行,要和并列是需设置RowSpan  ;从第二个单元格一次后合并8个
                    TableCell[1].Text = "书本数总计:" + mysum1.ToString()+"本";

                    TableCell.Add(new TableHeaderCell());
                    TableCell[2].ColumnSpan = 2;
                    TableCell[2].Text = "实样总计:" + mysum2.ToString()+"元";
                }
            }

  • 相关阅读:
    MyCat 数据库读写分离
    python 网络编程-05 socketserver
    python 网络编程-04 文件的传输
    python 网络编程-03 粘包问题及处理
    常用模块-01getopt
    js获取自动获取本电脑IP
    js变态需求
    js正则不能输入中文和英文
    禁止输入中文
    手机号3-4-5
  • 原文地址:https://www.cnblogs.com/happygx/p/1957932.html
Copyright © 2011-2022 走看看