i show u an example...this will be essier
javascript funtion; you just change the gridview name
function CalculateTotals()
{
var gv = document.getElementById("<%= gvPO.ClientID %>");
var tb = gv.getElementsByTagName("input");
var lb = gv.getElementsByTagName("span");
var sub = 0;
var total = 0;
var indexQ = 1;
var indexP = 0;
var price = 0;
var qty = 0;
var totalQty = 0;
var tbCount = tb.length / 2;
for (var i = 0; i < tbCount; i++)
{
if (tb[i].type == "text") {
ValidateNumber(tb[i + indexQ]);
sub = parseFloat(tb[i + indexP].value) * parseFloat(tb[i + indexQ].value);
if (isNaN(sub)) {
lb[i].innerHTML = "0.00";
sub = 0;
}
else {
lb[i].innerHTML = FormatToMoney(sub, " ", ",", "."); ;
}
if (isNaN(tb[i + indexQ].value) || tb[i + indexQ].value == "") {
qty = 0;
}
else {
qty = tb[i + indexQ].value;
}
totalQty += parseInt(qty);
total += parseFloat(sub);
indexQ++;
indexP++;
}
}
lb[lb.length - 2].innerHTML = totalQty;
lb[lb.length -1].innerHTML = FormatToMoney(total, " ", ",", ".");
}
<asp:GridView ID="gvPO" runat="server" AutoGenerateColumns="False"
CellPadding="4" GridLines="None" ShowFooter="True" DataKeyNames="ITEMCODE"
Width="776px" Height="167px"
ForeColor="#333333"
onrowdeleting="gvPO_RowDeleting" ondatabound="gvPO_DataBound"
onprerender="gvPO_PreRender" onrowdatabound="gvPO_RowDataBound"
>
<FooterStyle BackColor="#006699" Font-Bold="True" ForeColor="White" />
<RowStyle BackColor="#FFFBD6" ForeColor="#333333" />
<Columns>
<asp:BoundField DataField="ITEMCODE" HeaderText="Item Code"
SortExpression="ITEMCODE" />
<asp:BoundField DataField="ITEMDESCRIPTION" HeaderText="Description"
SortExpression="ITEMDESCRIPTION" />
<asp:TemplateField HeaderText="Qty">
<ItemTemplate>
<asp:Label ID="lblQty" runat="server" Text='<%# Eval("OPENINGQTY")%>' ></asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:Label ID="lblTotalqty" runat="server" Text="0"></asp:Label>
</FooterTemplate>
</asp:TemplateField>
<asp:BoundField DataField="ITEMUNIT" HeaderText="UOM"
SortExpression="ITEMUNIT" />
<asp:TemplateField HeaderText="Rate">
<ItemTemplate>
<asp:Label ID="lblPrice" runat="server" Text='<%# Eval("PURCHASERATE")%>' ></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Value">
<ItemTemplate>
<asp:Label ID="lbltotal" runat="server" Text='<%# Eval("SUBTOTAL")%>' ></asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:Label ID="lblSubtotal" runat="server" Text="0.00"></asp:Label>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="VAT %">
<ItemTemplate>
<asp:Label ID="lblVATpercentage" runat="server" Text='<%# Eval("VatPercentage")%>' ></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="VAT Total">
<ItemTemplate>
<asp:Label ID="lblVATtotal" runat="server" Text='<%# Eval("VatTotal")%>' ></asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:Label ID="lblVATtotal" runat="server" Text="0.00"></asp:Label>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Total Amount">
<ItemTemplate>
<asp:Label ID="lbltotalAmount" runat="server" Text='<%# Eval("TotalAmount")%>' ></asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:Label ID="lbltotalAmount" runat="server" Text="0.00"></asp:Label>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField >
<ItemTemplate>
<asp:LinkButton ID="LinkButton1"
CommandArgument='<%# Eval("ITEMCODE") %>'
CommandName="Delete" runat="server" OnClientClick="javascript:return confirm('Do you really want to \ndelete the item?');">
Delete</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<RowStyle CssClass="RowStyle" />
<PagerStyle CssClass="PagerStyle" />
<SelectedRowStyle CssClass="SelectedRowStyle" />
<HeaderStyle CssClass="HeaderStyle" />
<EditRowStyle CssClass="EditRowStyle" />
<AlternatingRowStyle CssClass="AltRowStyle" />
</asp:GridView>
protected void gvPO_RowDataBound(object sender, GridViewRowEventArgs e)
{
try
{
if (e.Row.RowType ==DataControlRowType.EmptyDataRow)
{
grdTotal = 0;
grdQty = 0;
grdVat = 0;
grdAmount = 0;
}
if (e.Row.RowType == DataControlRowType.DataRow)
{
int Qty = Convert.ToInt32(DataBinder.Eval(e.Row.DataItem, "OPENINGQTY"));
decimal SubTotal = Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "SUBTOTAL"));
decimal vat = Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "VatTotal"));
decimal TotalAmount = Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "TotalAmount"));
grdQty = grdQty + Qty;
grdTotal = grdTotal + SubTotal;
grdVat = grdVat + vat;
grdAmount = grdAmount + TotalAmount;
}
if (e.Row.RowType == DataControlRowType.Footer)
{
Label lbl = (Label)e.Row.FindControl("lblTotalqty");
lbl.Text = grdQty.ToString();
Label lb2 = (Label)e.Row.FindControl("lblSubtotal");
lb2.Text = grdTotal.ToString();
Label lb3 = (Label)e.Row.FindControl("lblVATtotal");
lb3.Text = grdVat.ToString();
Label lb4 = (Label)e.Row.FindControl("lbltotalAmount");
lb4.Text = grdAmount.ToString();
txtTotal.Text = grdAmount.ToString();
total = ConvertToINR(txtTotal.Text).ToString();
txtAmountInWords.Text = total.ToString();
}
}
catch (Exception)
{
// Response.Write("<script language='javascript'>alert('Data Table is null...');</script>");
}
}
i hope now you can do it.... All the very best......