zoukankan      html  css  js  c++  java
  • GriView 添加合并行 1

    前提:设置属性ShowFooter="True"
    方法一:
    使用SQL查询统计出合计值,在绑定GridView时让其结果赋于一个DataTable(全局变量),然后在RowDataBound事件中

    if (e.Row.RowType == DataControlRowType.Footer)
            
    {
                e.Row.Cells[
    0].Text = "合计";

                e.Row.Cells[
    3].Text = dtSum.Rows[0][0].ToString();
                e.Row.Cells[
    4].Text = dtSum.Rows[0][1
    ].ToString();
                e.Row.Cells[
    5].Text = dtSum.Rows[0][2
    ].ToString();
                e.Row.Cells[
    6].Text = dtSum.Rows[0][3].ToString();
                e.Row.Cells[
    7].Text = dtSum.Rows[0][4
    ].ToString();
                e.Row.Cells[
    8].Text = dtSum.Rows[0][5].ToString();
                e.Row.Cells[
    9].Text = dtSum.Rows[0][6
    ].ToString();
                e.Row.Cells[
    10].Text = dtSum.Rows[0][7
    ].ToString();
                e.Row.Cells[
    11].Text = dtSum.Rows[0][8
    ].ToString();
            }

    其中dtSum是那个全局DataTable,在绑定GridView同时将SQL查询的结果赋给它;效果如下:

    方法二、直接把对应列每一行的值相加(不做数据查询,在RowDataBound事件中运算)

    //注:必须先将ShowFooter属性设为true

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

                 //要统计计算和的列
                mysum1 
    +=Convert .ToInt32 (myrows[2
    ].ToString ());
                mysum2 
    += Convert.ToInt32(myrows[3
    ].ToString());
            }

            
    // 合计
            if (e.Row.RowType == DataControlRowType.Footer)
            
    {

                  //显示统计数的位置
                e.Row.Cells[
    0].Text = "合计";
                e.Row.Cells[
    1].Text =
     mysum1.ToString();
                e.Row.Cells[
    2].Text = mysum2.ToString();

            }

     }

     

    前提:设置属性ShowFooter="True"
    方法一:
    使用SQL查询统计出合计值,在绑定GridView时让其结果赋于一个DataTable(全局变量),然后在RowDataBound事件中

    if (e.Row.RowType == DataControlRowType.Footer)
            
    {
                e.Row.Cells[
    0].Text = "合计";

                e.Row.Cells[
    3].Text = dtSum.Rows[0][0].ToString();
                e.Row.Cells[
    4].Text = dtSum.Rows[0][1
    ].ToString();
                e.Row.Cells[
    5].Text = dtSum.Rows[0][2
    ].ToString();
                e.Row.Cells[
    6].Text = dtSum.Rows[0][3].ToString();
                e.Row.Cells[
    7].Text = dtSum.Rows[0][4
    ].ToString();
                e.Row.Cells[
    8].Text = dtSum.Rows[0][5].ToString();
                e.Row.Cells[
    9].Text = dtSum.Rows[0][6
    ].ToString();
                e.Row.Cells[
    10].Text = dtSum.Rows[0][7
    ].ToString();
                e.Row.Cells[
    11].Text = dtSum.Rows[0][8
    ].ToString();
            }

    其中dtSum是那个全局DataTable,在绑定GridView同时将SQL查询的结果赋给它;效果如下:

    方法二、直接把对应列每一行的值相加(不做数据查询,在RowDataBound事件中运算)

    //注:必须先将ShowFooter属性设为true

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

                 //要统计计算和的列
                mysum1 
    +=Convert .ToInt32 (myrows[2
    ].ToString ());
                mysum2 
    += Convert.ToInt32(myrows[3
    ].ToString());
            }

            
    // 合计
            if (e.Row.RowType == DataControlRowType.Footer)
            
    {

                  //显示统计数的位置
                e.Row.Cells[
    0].Text = "合计";
                e.Row.Cells[
    1].Text =
     mysum1.ToString();
                e.Row.Cells[
    2].Text = mysum2.ToString();

            }

     }

     

     

     

  • 相关阅读:
    TeamX 专为中小团队思考的...团队协作工具
    8 月直播课抢先看 | 代码质量实战 + 微服务项目实战课程报名中
    CODING DevOps 代码质量实战系列第一课,本周开讲!
    CODING 现已支持墨刀原型引入
    CODING 企业微信小程序上线了
    CODING DevOps + Nginx-ingress 实现自动化灰度发布
    第二届腾讯运维技术开放日来啦!
    前端智造,内容新生
    kafka的特性初探
    弄懂一致性哈希后我打通了redis分区集群的原理
  • 原文地址:https://www.cnblogs.com/happygx/p/1957900.html
Copyright © 2011-2022 走看看