Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Totaling a column in Datgrid

Reply
Thread Tools

Totaling a column in Datgrid

 
 
Atif Jalal
Guest
Posts: n/a
 
      01-21-2004
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
--
SUM AA
--
___________________________
 
Reply With Quote
 
 
 
 
Daniel Bass
Guest
Posts: n/a
 
      01-21-2004
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.

"Atif Jalal" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) om...
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
--
SUM AA
--
___________________________


 
Reply With Quote
 
 
 
 
Alvin Bruney
Guest
Posts: n/a
 
      01-24-2004
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));

--
Regards,
Alvin Bruney [ASP.NET MVP]
Got tidbits? Get it here...
http://tinyurl.com/3he3b
"Atif Jalal" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) om...
> 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
> --
> SUM AA
> --
> ___________________________



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
DatGrid Data Updating Steve Wark ASP .Net 2 05-01-2005 12:55 AM
datgrid and sql bit field SKG ASP .Net 2 06-16-2004 12:00 AM
insert a hyperlink column to datgrid TJS ASP .Net Datagrid Control 1 03-02-2004 02:59 PM
Dynamically created Datgrid will not enter Edit Mode! Mike ASP .Net 0 01-13-2004 06:00 PM
need help totaling one city at a time dan C++ 1 11-02-2003 09:05 PM



Advertisments