Calculate the Sum of the Bound field Column values using JavaScript
I have a GridView which consists of Five Bound Field Column Such 开发者_运维问答as AttributeName, Tax Percentage, Reference Amount, Sign, Tax Amount.
The GridView may have two rows or three rows or sometimes there would be no rows in the GridView.
Here I want to calculate the TaxAmount of all the rows in the GridView and I want to display the Total Tax amount into a Label.
I know how to do this in C#. But here, I want to do this in the Client Side itself using JavaScript. How to do this?
I think you will need to use "TemplateColumn" instead of "BoundColumn".
Here I changed the BoundField Column to TemplateField.
The answer for the above Question is
function CalculateTax()
{
var taxgrid = document.getElementById('<%=gvAttribute.ClientID %>');
var taxip = taxgrid.getElementsByTagName('input');
var taxamount = 0*1;
for(i = 0; i < taxip.length; i++)
{
var tax = taxip[i].value;
taxamount = parseFloat(taxamount) + parseFloat(tax);
}
document.getElementById('<%=TextBox1.ClientID %>').innerText = taxamount.toFixed(2)+ "/-";
}
精彩评论