• 统计合并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()+"元";
                }
            }

  • 相关阅读:
    HDU 1496 Equations
    HDU 1060 Leftmost Digit
    HDU 1391 Number Steps
    HDU 1212 Big Number
    HDU 1491 Octorber 21st
    HDU 1339 A Simple Task
    HDU 2710 Max Factor
    HDU 1176 免费馅饼
    FORTH基本堆栈操作
    FORTH 安装使用
  • 原文地址:https://www.cnblogs.com/happygx/p/1957932.html
Copyright © 2020-2023  润新知