Totaling a column in Datgrid

Discussion in 'ASP .Net' started by Atif Jalal, Jan 21, 2004.

  1. Atif Jalal

    Atif Jalal Guest

    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
    --
    ___________________________
    Atif Jalal, Jan 21, 2004
    #1
    1. Advertising

  2. Atif Jalal

    Daniel Bass Guest

    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" <> wrote in message
    news:...
    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
    --
    ___________________________
    Daniel Bass, Jan 21, 2004
    #2
    1. Advertising

  3. Atif Jalal

    Alvin Bruney Guest

    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" <> wrote in message
    news:...
    > 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
    > --
    > ___________________________
    Alvin Bruney, Jan 24, 2004
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mike
    Replies:
    0
    Views:
    389
  2. SKG

    datgrid and sql bit field

    SKG, Jun 15, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    1,054
    =?Utf-8?B?QW5keSBaIFNtaXRo?=
    Jun 16, 2004
  3. =?Utf-8?B?UnViZW4=?=

    DatGrid.DataSource

    =?Utf-8?B?UnViZW4=?=, May 21, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    446
    Lucas Tam
    May 21, 2005
  4. dan
    Replies:
    1
    Views:
    343
    Thomas Matthews
    Nov 2, 2003
  5. TJS

    insert a hyperlink column to datgrid

    TJS, Feb 27, 2004, in forum: ASP .Net Datagrid Control
    Replies:
    1
    Views:
    128
    Alvin Bruney [MVP]
    Mar 2, 2004
Loading...

Share This Page