Totaling a column in Datgrid

A

Atif Jalal

Hi,
I would like to know if there is a way to print 'Sum' of all the
values of one of the columns in a datagrid in an ASP.net application
using vb.net. The Sum should be displayed all the way at the end below
the column values.

Like:
___________________________
Column1 Column2 Column3
___________________________
XX
YY
ZZ
 
D

Daniel Bass

one way to do this would be to forget the datagrid, but rather look at the
source...
if the source is a table, for example, you could easily enumerate through
the rows at that column, and tally up the value, then create a new row which
has a column for that total.
if the source isn't a table, convert it to one and make the table the data
source.

hope that helps.
Dan.

Hi,
I would like to know if there is a way to print 'Sum' of all the
values of one of the columns in a datagrid in an ASP.net application
using vb.net. The Sum should be displayed all the way at the end below
the column values.

Like:
___________________________
Column1 Column2 Column3
___________________________
XX
YY
ZZ
 
A

Alvin Bruney

One approach is to insert the subtotal into the footer row of the datagrid
in the itemdatabound routine.

if(e.itemtype == listitemtype.footer)
string strCol = columname;
e.item.cells[0].Columnspan = 2;
e.item.cells[0].Text = "Sum";
e.item.cells[0].BackColor= Color.LimeGreen;
e.item.cells[1].Text =
ds.Tables[0].Compute("Sum(["+strCol+"])",String.Empty));
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top