在gridview中显示总和(Show sum In gridview)

   IT问题网   2020-06-26 00:00:00

问 题

我的gridview的数据如下所示(例如)

 col1 col2 col3 
2 10 1
4 3 5
11 15 18






我要做的是......通过以下方式执行行和列并向网格添加另一列...所以最终它将如下所示



 col1 col2 col3总计
2 10 1 13
4 3 5 12
11 15 18 44

17 28 24

解决方案

在从数据库中检索值时,您可以通过编写这样的查询来获取行总数



 select col1,col2,col3,col1 + col2 + col3 as total from tablename 




为了获得列总数,请写出像


 select sum(col1)为tot1,sum(col2)为tot2,sum(col3)为tot3 from tablename 

<块quote>
  create   table 测试

num1 int
num2 int
num3 int
num4 int


insert into 测试 values 1 2 3 4

select num1,num2,num3,num4,(num1 + num2 + num3 + num4) as total from 测试

drop table 测试


it将结果 in

num1 num2 num3 num4 total
1 2 3 4 10

标签:显示总和



分享:

  • 微信
  • QQ好友
  • QQ空间
  • 新浪微博


热门推荐

Ajax客户端脚本错误(Ajax Client side script error)

problem if (typeof(sys) === #39;undefined#39; ...

如何在UP和DOWN键进行编码(How to code at the UP and DOWN key)

problem i want to move picture box up and down when a use ...

如何计算excel 2003中的时间平均值(how to calculate time averge in excel 2003)

problem hii to all. if any body knows how to calculateave ...

控制相关问题(Control related issue)

problem respected sir, i have a page in which i m gettin ...

在运行时动态绘制div(draw div dynamically at runtime)

problem hiii all, i have a page which i draw all its attr ...

转换数据库值(Convert a databse value)

problem i have a table one field is price and ...

如何使单元格的内容可见为false(How do i make the content of a cell visible false)

problem how do i make the content of a cell visible false ...

qtwebkit并连接cpp和javascript(qtwebkit and connect cpp and javascript)

problem hi to all i am using qwebkit i have a cpp object ...

response.flush&amp;到Response.End(problem with response.flush &amp; response.end)

problem hello everybody, i have used response.flush() wi ...

ShellExecute()不执行(ShellExecute() Not Executing)

problem i''m running a batch file from c++ code.when i ru ...

Radion Button使用Javascript隐藏/可见(Radion Button Hide/Visible Using Javascript)

problem i want hide/visible radio button using javascript ...

如何在此xml文件中插入/删除节点(how to insert/delete a node to this xml file)

problem hi all :) i search in webto find a code that ins ...

XML + DTD,不会出现在浏览器中(XML + DTD, won&#39;t show up in browser)

problem my code looks right, validates, but when i open i ...

什么是样品反射(What is Reflection with sample)

problem hi everybody, could u plz tell me reflection d ...

在封闭网络上获取设备的IP地址(optaining IP addresses of devices on a closed network)

problem i have a situation where i have multiple devices ...

如何限制用户在asp.net中通过javascript在TextBox中仅输入alphabates(How to Restrict user to enter only alphabates in TextBox by javascript in asp.net)

problem how to restrict user to enter onlyalphabates in t ...

如何在远程服务器上使用jquery调用webservice?(how to call webservice using jquery on remote server)

problem i have created one html page,in that using jquery ...

pchealth文件夹占用了大量空间(pchealth folder consuming a lot of space)

problem in my server there are plenty of cab ...

如何在vb.net网站中添加c#名称空间?(How can add c# namespace in a vb.net Website)

problem hello codian, i want to create two namespaces in ...

仅搜索已更改的目录(Search Only Changed Directory(s))

problem i''m running this batch that works pr ...