首先,在页面添加事件<ASP:GridView OnRowDataBound="Gridview1_DataBound">

  其次,后台具体方法:

public void Gridview1_DataBound(object sender, System.Web.UI.WebControls.GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                if (((Label)e.Row.FindControl("IF_VALID")).Text.ToString().Trim() == "作废")
                {
                    e.Row.BackColor = System.Drawing.Color.LightGray;
                }

                if (e.Row.RowType == DataControlRowType.DataRow)
                {
                    string current01 = String.Format("{0:0.00}", DataBinder.Eval(e.Row.DataItem, "COST_NAME"));

                    switch (current01) { case "": total01 += 0; break; default: total01 += Convert.ToDouble(current01); break; }
                }
                

                if (e.Row.RowType == DataControlRowType.Footer)
                {
                    e.Row.Cells[8].Text = "运输成本小计:";
                    e.Row.Cells[9].Text = string.Format("{0:#,##0.00}", total01);

                    Response.Write("<script language ='javascript'> window.parent.document.getElementById('yscb').value=" + total01 + ";</script> ");

                    Response.Write("<script language ='javascript'> window.parent.cal_ct_profit();</script> ");
                }

                string ywcb;
                string yscb;
                string kpfy;
                double profit = 0;

                ywcb = DataBinder.Eval(e.Row.DataItem, "COST_NAME").ToString();
                yscb = DataBinder.Eval(e.Row.DataItem, "COST_YUNSHU").ToString();
                kpfy = DataBinder.Eval(e.Row.DataItem, "Exhibit_amount").ToString();

                switch (ywcb) { case "": profit -= 0; break; default: profit -= double.Parse(ywcb); break; }
                switch (yscb) { case "": profit -= 0; break; default: profit -= double.Parse(yscb); break; }
                switch (kpfy) { case "": profit += 0; break; default: profit += double.Parse(kpfy); break; }

                e.Row.Cells[profit_column].Text = String.Format("{0:0.00}", profit);

                if (profit < 0)
                {
                    e.Row.Cells[profit_column].ForeColor = System.Drawing.Color.Red;
                }

                //string current01 = String.Format("{0:0}", DataBinder.Eval(e.Row.DataItem, "CARTON20_COUNT"));
                //string current02 = String.Format("{0:0}", DataBinder.Eval(e.Row.DataItem, "CARTON40_COUNT"));
                //string current03 = String.Format("{0:0}", DataBinder.Eval(e.Row.DataItem, "CARTON45_COUNT"));
                string current04 = String.Format("{0:0.00}", DataBinder.Eval(e.Row.DataItem, "COST_NAME"));
                string current05 = String.Format("{0:0.00}", DataBinder.Eval(e.Row.DataItem, "COST_YUNSHU"));
                string current06 = String.Format("{0:0.00}", DataBinder.Eval(e.Row.DataItem, "Exhibit_amount"));
                
                //switch (current01) { case "": total01 += 0; break; default: total01 += int.Parse(current01); break; }
                //switch (current02) { case "": total02 += 0; break; default: total02 += int.Parse(current02); break; }
                //switch (current03) { case "": total03 += 0; break; default: total03 += int.Parse(current03); break; }

                switch (current04) { case "": total04 += 0; break; default: total04 += double.Parse(current04); break; }
                switch (current05) { case "": total05 += 0; break; default: total05 += double.Parse(current05); break; }
                switch (current06) { case "": total06 += 0; break; default: total06 += double.Parse(current06); break; }
                //total07 += profit;
            }

            total00 = GridView1.Rows.Count;

            ShowPageStatus(string.Format("{0:#,##0}", total00), total04, total05, total06);

        }

        private void ShowPageStatus(string nRecords, double ywcb, double yscb, double kpfy)
        {
            ShowTTL.Text = "总计<b><FONT color= #9C0001> " + nRecords + " </FONT></b>箱,  出车费<b><FONT color= #9C0001> " + ywcb + " </FONT></b>元,  运输费<b><FONT color= #9C0001> " + yscb + " </FONT></b>元,  亏盈金额<b><FONT color= #9C0001> " + kpfy + " </FONT></b>元";
        }

        private void ShowCTTTL(double T20, double T40, double T45)
        {
            ShowCount.Text = "20尺 <b><FONT color= #9C0001> " + T20 + " </FONT></b>, 40尺 <b><FONT color= #9C0001> " + T40 + " </FONT></b>, 45尺 <b><FONT color= #9C0001> " + T45 + " </FONT></b>。";
        }

GridView中数据的汇总方法的更多相关文章

  1. GridView中数据行的操作

    一个是直接动态绑定gridview 用3楼的办法就可以了 int j=1;//j的数值表示你要取的那一列的索引,要取第二列,j就设为1for (int i = 0; i < this.GridV ...

  2. Repeater 和 GridView 中数据格式化

    GridView中显示两位小数: <asp:BoundField DataField="investmoney" DataFormatString="{0:f2}& ...

  3. 【转】GridView中页脚汇总显示

    来源:http://blog.csdn.net/atian15/article/details/3495514 有时候需要在GridView的页脚中汇总显示一些信息,常见的方法有两种: 1.在SQL中 ...

  4. MongoDB 中数据的替换方法实现 --类Replace()函数功能

    关键字: MongoDB,Replace,forEach 近日接到一个开发需求,因业务调整,需要DBA协助,将MongoDB数据库中某集合的进行替换.例如我们需要将集合A中B字段中,有关<美好& ...

  5. PyQt学习随笔:Model/View设计中支持视图中数据修改的方法及步骤

    老猿Python博文目录 专栏:使用PyQt开发图形界面Python应用 老猿Python博客地址 要支持视图中的数据可以修改,需要两个步骤: 1. 在视图中设置editTriggers属性支持在视图 ...

  6. JS中数据类型转换

    JS中数据类型转换汇总 JS中的数据类型分为 [基本数据类型] 数字 number 字符串 string 布尔 boolean 空 null 未定义 undefined [引用数据类型] 对象 obj ...

  7. 通过删除hbase表中的region来达到删除表中数据

    公司最近在搞一个hbase删除数据,由于在建表的时候是通过region来对每日的数据进行存储的,所以要求在删除的时候直接通过删除region的来删除数据(最好的方案是只删除region中的数据,不把r ...

  8. .net中从GridView中导出数据到excel(详细)

    1,创建数据源 找到要导出的GridView中的数据. 2,重写VerifyRenderingInServerForm方法. public override void VerifyRenderingI ...

  9. 一个在ASP.NET中利用服务器控件GridView实现数据增删改查的例子

    备注:这是我辅导的一个项目开发组的一个例子,用文章的方式分享出来,给更多的朋友参考.其实我们这几年的项目中,都不怎么使用服务器控件的形式了,而是更多的采用MVC这种开发模式.但是,如果项目的历史背景是 ...

随机推荐

  1. XSL学习笔记4 XSLT模式匹配的语法

    模板规则通过使用模式来匹配文档树的节点.模式指定一组条件,用于选择要处理的节点.   模式匹配的语法不光可以在<xsl:template>元素的match属性中使用,还可以在<xsl ...

  2. 代码在ie9中不能正确执行

    <!DOCTYPE html> <html> <head lang="zh"> <meta charset="UTF-8&quo ...

  3. MySQL多表查询

    第一种: select a.a1,a.a2,a.a3,b.b2,c.c2,d.d2 from a,b,c,d where a.a1=b.b1 and b.b1=c.c1 and c.c1=d.d1 第 ...

  4. js学习笔记之标准库

    在全局函数中,this等于window  在函数被作为某个对象的方法调用时,this等于那个对象. 数组的函数: 检测:Array.isArray() 转换:toString(),toLocalStr ...

  5. db2定界符

    在DB2数据库中,在导出DEL文件时,默认的字符分隔符是".字段分隔符是, (逗号).有一个需求是要为Oracle数据库提供数据,因此就想使用"|"作为数据的字段分隔符. ...

  6. JavaScript-String基础知识

    1.字符串可以0个或多个字符串放在一起:     " ' '    ".'""' . "\"\""       2.写法 ...

  7. jquery中focus()失效怎么解决

    又学到一个新的知识! 今天在写表单验证的时候遇到一个关于获取焦点的focus()问题. 场景说明:在验证密码输入格式不对之后,弹出alert()提示框,提示密码不对,请重新输入.同时清空密码框并获得焦 ...

  8. ajax+div 代替iframe 学习尝试

    工作的时候遇到了所谓html内多tab展示的情况,主要是通过iframe来关联子页面: 不过也不知道从何时开始记得是说iframe不建议多用,所以想想,还是找找有没有其他方法(不应用于工作): 先说下 ...

  9. java并发编程(十九)障碍器CyclicBarrier

    转载请注明出处:http://blog.csdn.net/ns_code/article/details/17512983 CyclicBarrier(又叫障碍器)同样是Java 5中加入的新特性,使 ...

  10. nodejs学习之events

    在node里许多对象都发出事件:一个net.Server对象每次一个连接到来,都发出一个事件,一个fs.readStream对象在文件打开时放出一个事件.所有能放出事件的对象都是event.Event ...