tags:

views:

33

answers:

2

Suppose In database their is column called INCOME_PER_DAY. I bring data of this column in the gridview .

Now My question is that I want to find the total sum of the column INCOME_PER_DAY using C# .how to do this?

Please tell me.

A: 

Unfortunately, you have to loop through the column and add up rows line-by-line.

Statler
+1  A: 

Do this on server-side (database).

Return 2 recordsets: one with details and the second one (one row) with SUM(INCOME_PER_DAY).

or use this query:

SELECT ROW_TYPE = 1, FIELD1, FIELD2, FIELD3, INCOME_PER_DAY FROM MYSALES
UNION ALL
SELECT ROW_TYPE = 2, NULL, NULL, NULL, INCOME_PER_DAY = SUM(INCOME_PER_DAY) FROM MYSALES

ROW_TYPE = 1 - detail row ROW_TYPE = 2 - summary row

On a page, use, for example, datagrid in the ItemDataBound event handler: check ROW_TYPE to apply valid CSS style (detail and summary)

igor