Click here to Skip to main content
15,899,124 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
The below code returning the total sum of the a particular column in gridview that column consists of textbox control in each and every row..

here im using javascript to calculate the sum.. the process is working fine.. but the problem here is with the label control to which im assigning the result. When i'm assigning the total result to label.. it's showing the exact result for a moment.. fyn.. but after few seconds the label is getting refresh and storing the old value.. how to resolve it..

Note: the label here is under the update panel

here is the label control that which i'm using.


C#
<asp:Label ID="lblTotalAmtText" runat="server" CssClass="mediumblue" Text="0.00" />


What I have tried:

JavaScript
function getsum() {
try {
      var table = document.getElementById('GrdData'); //GrdData is the grid ID
      var sum = 0;
      for (var i = 1; i < table.rows.length; i++)       
      {
        if (!isNaN(table.rows[i].cells[0].innerText)) 
        {
         if (sum == 0) {
         sum =            (parseFloat(table.rows[i].cells[4].firstChild.value)).toString();}
         else {
         sum = (parseFloat(sum) +  parseFloat(table.rows[i].cells[4].firstChild.value)).toString();
         }                       //alert(parseFloat(table.rows[i].cells[4].childNodes[0].value));
        }
      }
     document.getElementById('lbltotalamttext').innerHTML = sum;
    //here is the culprit lbltotalamttext
  }
catch (ex) {
 alert(ex.message)
 }
}
Posted
Updated 2-Jul-16 3:08am
v2
Comments
Karthik_Mahalingam 2-Jul-16 9:32am    
does the page is getting refreshed on timer or something?
JanardhanSharma 4-Jul-16 1:27am    
Nope, It's refreshing only the label Control

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