CodeCharge Studio
search Register Login  

Web Reports

Visually create Web Reports in PHP, ASP, .NET, Java, Perl and ColdFusion.
CodeCharge.com

YesSoftware Forums -> CodeCharge Studio -> .NET

 sum column editable grid

Print topic Send  topic

Author Message
jchase

Posts: 3
Posted: 09/26/2007, 11:43 AM

Newbie to CCS...I've trolled the forums and help, have not found a way that worked.

How does one SUM a column in an editable grid?

After user entry I need to sum and validate the amount is not over a certain number.

Any insight is appreciated.

John Chase
View profile  Send private message
Nicole

Posts: 586
Posted: 09/27/2007, 2:03 AM

John,
I think that you can sum and validate editable grid's column on a client side. You can try the same solution as me, it works for me on both VB and C#.NET pages.
Before you start I recommend that you read this article that explains how to access the editable grid controls http://forums.codecharge.com/posts.php?post_id=60507
I'm using the same approach in my solution.
1. create custom function that calculates sum on editable grid's column:
  
function calc_sum(){  
	var sum;  
	sum = 0;  
	initarticlesElements();  
	for(var j = 0; j < articlesElements.length; j++){    
 	if (articlesElements[j][articlesTextBox1ID].value)   
	 	sum += parseInt(articlesElements[j][articlesTextBox1ID].value);  
	}  
	return sum;  
}  
  
</script>  
</head>  
You see that in my case the form's name is "articles" and textbox's name is "TextBox1".

2. I created a special DIV tag which I'm using to output sum value. I located it right above navigator:
  
<div id="sumValue"></div>  
              <!-- BEGIN Navigator Navigator -->  
...  
3. Then I call the calc_sum function three times:
3.1 on form's onLoad client side event:
  
document.getElementById("sumValue").innerHTML = "<b>Total=" + calc_sum() +"</b>";  
3.2 on onChange event (client side) of TextBox1 control
  
document.getElementById("sumValue").innerHTML = "<b>Total=" + calc_sum() +"</b>";  
3.3 and in onClick (client side) event of form's Submit button. Here I validate the value:
  
var submit_sum;  
submit_sum = calc_sum();  
if (parseInt(submit_sum)>40){  
   document.getElementById("sumValue").innerHTML = "Category Total=<b>" + submit_sum +"</b>";  
   alert('Sum is greater than 40');  
   return false;  
}  
  
Hope it helps.

Nicole

_________________
Regards,
Nicole
View profile  Send private message
Tuong Do
Posted: 09/27/2007, 6:06 PM

Hi John



Assume you have an Edittable Grid name "PurchaseOrder"
There will be a field call "OrderAmount" of type Float

In the Onvalidate event of the Editable Grid, add a custome code

<Code>
'EditableGrid PurchaseOrder Event OnValidate. Action Custom Code @9-73254650
' -------------------------
' Write your own code here.
Dim MaxTotalOrderAmount as Double = 10000
Dim TotalOrderAmount as Double = 0

Dim OrderAmountValues As ArrayList = New ArrayList()
Dim itm As PurchaseOrderItem
For Each itm in items
If Not itm.IsEmptyItem AndAlso NOT itm.IsDeleted then
TotalOrderAmount = TotalOrderAmount +
itm.OrderAmount.value
End If
Next
If TotalOrderAmount > MaxTotalOrderAmount Then
items(0).errors.Add("MaxAmount_","Total Order Amount is more
than $" & MaxTotalOrderAmount.ToString())
BindAllowed = False
End If
' -------------------------
'End EditableGrid PurchaseOrder Event OnValidate. Action Custom Code
</code>

"jchase" <jchase@forum.codecharge> wrote in message
news:846faa8394d1fa@news.codecharge.com...
> Newbie to CCS...I've trolled the forums and help, have not found a way
> that
> worked.
>
> How does one SUM a column in an editable grid?
>
> After user entry I need to sum and validate the amount is not over a
> certain
> number.
>
> Any insight is appreciated.
>
> John Chase
> ---------------------------------------
> Sent from YesSoftware forum
> http://forums.yessoftware.com/
>

jchase

Posts: 3
Posted: 10/01/2007, 5:28 AM

Thanks to respondents, I got this working via client side scripting, similar to the approach Nicole suggested.

John Chase
View profile  Send private message
kieuale

Posts: 8
Posted: 04/09/2008, 4:25 PM

Nice script, but how do you access the control when its a LABEL?
View profile  Send private message

Add new topic Subscribe to topic   


These are Community Forums for users to exchange information.
If you would like to obtain technical product help please visit http://support.yessoftware.com.

Internet Database

Visually create Web enabled database applications in minutes.
CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


Powered by UltraApps Forum created with CodeCharge Studio
Copyright 2003-2004 by UltraApps.com  and YesSoftware, Inc.