title: Get sum of gridview textboxes values and show total in label using javascript
body: <p>I have in my application a grid-view in which a number of textboxes as template field, which can be incremented.When i enter some value in first textbox the sum of all textbox should be shown in Label. I have tried to use the below code but it didn't work.</p>
  
  <p><strong>JavaScript</strong></p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
      function calculate() {
          var txtTotal = 0.00;
  
          $(".calculate").each(function (index, value) {
              var val = value.value;
              val = val.replace(",", ".");
              txtTotal = MathRound(parseFloat(txtTotal) + parseFloat(val));
          });
  
          document.getElementById("&lt;%= lbltotal.ClientID %&gt;").value = txtTotal.toFixed(2);
      }
  
      function MathRound(number) {
          var result = Math.round(number * 100) / 100;
          return result;
      }
  &lt;/script&gt;
  </code></pre>
  
  <p><strong>GridView</strong></p>
  
  <pre><code>&lt;asp:GridView ID="GridView1" runat="server" ShowFooter="true" AutoGenerateColumns="false"&gt;
      &lt;Columns&gt;
          &lt;asp:BoundField DataField="RowNumber" HeaderText="Row Number" /&gt;
          &lt;asp:BoundField DataField="Description" HeaderText="Item Description" /&gt;
          &lt;asp:TemplateField HeaderText="Amount"&gt;
              &lt;ItemTemplate&gt;
                  &lt;asp:TextBox ID="txtamount" onkeyup="calculate();" CssClass="calculate" runat="server" Text=""&gt;&lt;/asp:TextBox&gt;
              &lt;/ItemTemplate&gt;
  
          &lt;/asp:TemplateField&gt;
      &lt;/Columns&gt;
  &lt;/asp:GridView&gt;
  </code></pre>
  
  <p><strong>label</strong></p>
  
  <pre><code>&lt;asp:Label ID="lbltotal" runat="server" Text="" ForeColor="Green"&gt;&lt;/asp:Label&gt;
  </code></pre>