Hello.
I'm looking to total a gridview column using jquery.
I have a javascript function that does the initial calculations then calls the calculate jquery function that is supposed to total the column.
Getting an object expected error at present.
Javascript calculation code below.
function multiply(Rate, number, total) {
var grid = document.getElementById('GridView1');
var num = parseFloat(document.getElementById(number).value);
var tot = document.getElementById(total);
var totValue = parseFloat(((Rate * num)));
var totValueRound = Math.round(totValue);
var totValueRound = totValue;
tot.innerHTML = "$" + totValue.toFixed(2);
calculate();
Jquery code to calculate the column below.
<script src="jquery-1.7.1.min.js" type="text/javascript"></script>
<script language="javascript" type="text/javascript">
function calculate() {
var values = 0;
$(".total").each(function(){
values += parseInt($(this).html());
$("#lblTotalAmount").html(values);
}
</script>
Mark up below
<asp:GridView ID="GridView1" runat="server"
AutoGenerateColumns="False" OnRowDataBound="GridView1_RowDataBound"
DataSourceID="AccessDataSource1"
ShowFooter="True" style="margin-bottom: 0px">
<Columns>
<asp:TemplateField HeaderText="Devices And Services" Visible="True" HeaderStyle-HorizontalAlign="Left" FooterText="Payable monthly in advance (excluding Agreement items):" ItemStyle-BackColor="#CCCCCC">
<ItemTemplate>
<asp:Label ID="lblItemDescription" runat="server" Width="382"
Text='<%# Eval("itemDescription") %>'></asp:Label>
</ItemTemplate>
<HeaderStyle HorizontalAlign="Left"></HeaderStyle>
</asp:TemplateField>
<asp:TemplateField HeaderText="Rate">
<ItemTemplate>
<asp:Label ID="lblRate" runat="server" width="50" ></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Number" ControlStyle-BackColor="#FFFFCC">
<ItemTemplate>
<asp:TextBox ID="txtBoxNumber" Width="100px"
runat="Server" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Total" ItemStyle-CssClass="total">
<ItemTemplate>
<asp:Label ID="lblTotal" runat="Server" Width="106" />
</ItemTemplate>
<FooterTemplate>
<asp:Label ID="lblTotalAmount" runat="server" />
</FooterTemplate>
</asp:TemplateField>
</Columns>
<FooterStyle Font-Bold="True" />
</asp:GridView>