Click here to Skip to main content
16,010,544 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to calculate sum of textboxes in single column of gridview using javaScript.
When value of any textbox changes the value will be automatically calculated with new one...

I tried the script

C#
function CalculateTotals() {
           alert("dfhg");
           var grid = document.getElementById("rptExpense");
           var txt = document.getElementById("txtVFareTotal");
           alert(txt.value);
           for (var i = 0; i < 6; i++) {
               var val = grid.rows[i].columns[3].getElementById("txtexpense");
               alert(val.value);
           }



Plz help
Posted
Updated 17-Sep-13 23:17pm
v2
Comments
Thanks7872 18-Sep-13 5:04am    
Have you tried some thing?
sumit wagh 18-Sep-13 5:12am    
yes i tried so may ways but cant find textbox values in gridview
Thanks7872 18-Sep-13 5:14am    
Use improve question widget above and post the relevant code you have implemented till now and point out the problem you faced/suspected.

1 solution

Hey Sumit,

You can use jquery which is easy to use and need to write less lines of code. Use any class like 'Amount' on text boxes and use that class in jquery selector.

JavaScript
function CalculateTotals() {
           
         var total=0;
           $('.Amount').each(function(){
              total+=parseFloat($(this).val());
           });
$("#txtVFareTotal").val(total);
}


I hope it will work for you.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900