Running totals in gridview (when you have many totals required)

Discussion in 'ASP .Net' started by =?Utf-8?B?Um9iZXJ0IENoYXBtYW4=?=, Feb 15, 2007.

  1. Hi, Fairly easy to create one running total for a gridview but what if you
    have dozens of them?

    I have a gridview that allows bulk editing (all rows at once) and have it
    set up so that, on data binding, totals are created for all of the dozens of
    columns.

    However I need to have it so that any time someone changes a number in one
    of the textboxes the totals recalculate (columns need to add up to 100% so
    the totals act as a guide to users of whether the values total correctly).
    Can anyone suggest the best general approach for this client-side feature?

    TIA,

    Rob
     
    =?Utf-8?B?Um9iZXJ0IENoYXBtYW4=?=, Feb 15, 2007
    #1
    1. Advertising

  2. On Feb 15, 9:46 pm, Robert Chapman
    <> wrote:
    > Hi, Fairly easy to create one running total for a gridview but what if you
    > have dozens of them?
    >
    > I have a gridview that allows bulk editing (all rows at once) and have it
    > set up so that, on data binding, totals are created for all of the dozens of
    > columns.
    >
    > However I need to have it so that any time someone changes a number in one
    > of the textboxes the totals recalculate (columns need to add up to 100% so
    > the totals act as a guide to users of whether the values total correctly).
    > Can anyone suggest the best general approach for this client-side feature?
    >


    client-side = JavaScript

    You need to fire a javascript onchange and get the values from each
    textbox.

    I think you can find this thread helpful
    http://p2p.wrox.com/topic.asp?TOPIC_ID=51682
     
    Alexey Smirnov, Feb 15, 2007
    #2
    1. Advertising

  3. Re: Running totals in gridview (when you have many totals required

    Hi Alexey,

    I've seen that thread and am comfortable with using javascript to add a
    running total for specific textboxes. I get less sure of what to do when
    there are 50 columns to total and the number of rows is variable. What works
    well for one total doesn't really work for 50, so I just need a little
    guidance as to what route to take.

    Regards,

    Rob

    "Alexey Smirnov" wrote:

    > On Feb 15, 9:46 pm, Robert Chapman
    > <> wrote:
    > > Hi, Fairly easy to create one running total for a gridview but what if you
    > > have dozens of them?
    > >
    > > I have a gridview that allows bulk editing (all rows at once) and have it
    > > set up so that, on data binding, totals are created for all of the dozens of
    > > columns.
    > >
    > > However I need to have it so that any time someone changes a number in one
    > > of the textboxes the totals recalculate (columns need to add up to 100% so
    > > the totals act as a guide to users of whether the values total correctly).
    > > Can anyone suggest the best general approach for this client-side feature?
    > >

    >
    > client-side = JavaScript
    >
    > You need to fire a javascript onchange and get the values from each
    > textbox.
    >
    > I think you can find this thread helpful
    > http://p2p.wrox.com/topic.asp?TOPIC_ID=51682
    >
    >
    >
     
    =?Utf-8?B?Um9iZXJ0IENoYXBtYW4=?=, Feb 16, 2007
    #3
  4. Re: Running totals in gridview (when you have many totals required

    On Feb 16, 11:57 am, Robert Chapman
    <> wrote:
    > Hi Alexey,
    >
    > I've seen that thread and am comfortable with using javascript to add a
    > running total for specific textboxes. I get less sure of what to do when
    > there are 50 columns to total and the number of rows is variable. What works
    > well for one total doesn't really work for 50, so I just need a little
    > guidance as to what route to take.


    If I understand it right it might be following

    in codebehind you will add onchanged JS with reference to some JS to
    recalculate total

    In the same time you can calculate the current total, number of rows,
    etc. and set it to a public variable, which can be used later in
    client side JS.

    -- javascript --

    var numberOfRows=<%=numberOfRows%>

    .....

    Depends on implementation, if you have a maximum possible number of
    rows (say <25) you may not need to have the numberOfRows because you
    can enumerate your rows like

    for (var i=1;i<25;i++) {
    if (mytextbox == null) {
    return; // if you have a null between 1..25 it means you have less
    rows
    } else {
    total += mytextbox.value;
    }
    }

    I think that you need a similar solution, as in the following thread:
    http://groups.google.com/group/micr...read/thread/5b45636ffff3bfcd/acadfd47b1745c36
     
    Alexey Smirnov, Feb 16, 2007
    #4
    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. John

    adding totals in gridview rows

    John, Jun 9, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    605
  2. dave
    Replies:
    1
    Views:
    610
    Bruno Alexandre
    Feb 14, 2007
  3. shoplifes
    Replies:
    0
    Views:
    311
    shoplifes
    Nov 25, 2007
  4. winter heat
    Replies:
    0
    Views:
    101
    winter heat
    Nov 1, 2010
  5. damezumari
    Replies:
    18
    Views:
    332
    Richard Cornford
    Dec 20, 2006
Loading...

Share This Page