在GridView中显示总和 [英] Show sum In gridview

查看:93
本文介绍了在GridView中显示总和的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

my gridview has data which looks like below (for example)

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




我想做的是...按行和列进行求和,然后将另一列添加到网格中,以便最终看起来像下面的




What I am trying to do is ... performing a sum by Row and Column and add another column to grid ... So that ultimately it will looks like below

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

17      28     24

推荐答案

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

At the time of Retrieving values from database, you can get the row total by writing query like this

SELECT col1,col2,col3,col1+col2+col3 as total FROM tablename



为了获得列总数,请编写类似
的查询



In order to get column total write the query like

SELECT sum(col1) as tot1,sum(col2) as tot2,sum(col3) as tot3 FROM tablename


CREATE TABLE TESTING
(
NUM1 INT,
NUM2 INT,
NUM3 INT,
NUM4 INT
)

INSERT INTO TESTING VALUES (1,2,3,4)

SELECT NUM1,NUM2,NUM3,NUM4,(NUM1+NUM2+NUM3+NUM4) AS TOTAL FROM TESTING

DROP TABLE TESTING


IT WILL RESULT IN 

NUM1	NUM2	NUM3	NUM4	TOTAL
1	2	3	4	10


这篇关于在GridView中显示总和的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆