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 |