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

G

Guest

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
 
G

Guest

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
 
G

Guest

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
 
G

Guest

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
 

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,744
Messages
2,569,484
Members
44,906
Latest member
SkinfixSkintag

Latest Threads

Top