I have a GridView with three COlumns Which will be like this:
ID Sign Amount
------ -------- ---------
1 + 1000
2 - 500
3 - 750
So the Sum of the Column “Amount” Should be “-250”. Consider the Column “Sign” also with the Amount.
Here is my GridView’s Source Code:
<Columns>
<asp:BoundField DataField="ID" HeaderText="ID"/>
<asp:TemplateField HeaderText="Sign" >
<ItemTemplate>
<asp:TextBox ID="txtgvSign" runat="server" Text='<%# Bind("Sign") %>'></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Amount">
<ItemTemplate>
<asp:TextBox ID="txtAmount" runat="server" Text='<%# Bind("Amount") %>'></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
</Columns>
So far, I have written One JavaScript, But It Only Calculate the Sum of Amount. I dont know how to calculate the Sum based on the Sign values. Below is the JavaScript I have written:
function CalculateTax(fixedtotal)
{
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);
}
return parseFloat(fixedtotal) + parseFloat(taxamount);
}
So Please Make Changes to this Javascript.
can you try the below code?