[Solved] ASP.Net GridVeiw column Multiply is not working with TemplateField using jQuery

akhter
 
on May 23, 2022 01:37 AM
440 Views

as per reference

[Solved] Multiply two columns in ASP.Net GridView using jQuery

I change column from

<asp:BoundField ItemStyle-Width="150px" DataField="rate" HeaderText="Rate" />

To

<asp:TemplateField HeaderText="Rate">
    <ItemTemplate>
        <asp:Label ID="rate" Width="50px"  runat="server" Text='<%#Bind("rate")%>'></asp:Label>
    </ItemTemplate>
</asp:TemplateField>                   

Then multiplication is not working

Download FREE API for Word, Excel and PDF in ASP.Net: Download
dharmendr
 
on May 23, 2022 01:40 AM

Hi akhter,

Use below code.

<script type="text/javascript">
    $(function () {
        $("[id*=orderqty]").val("0");
        $("body").on("change keyup", "[id*=orderqty]", function () {
            //Check whether Quantity value is valid number.
            var quantity = $.trim($(this).val());
            if (isNaN(quantity)) {
                quantity = 0;
            }
            //Update the Quantity TextBox.
            $(this).val(quantity);

            var row = $(this).closest("tr");

            //Check whether Rate value is valid number.
            var rate = $("[id*=rate]", row).html();
            if (isNaN(rate)) {
                rate = 0;
            }
            $("[id*=rate]", row).html(rate);

            //Calculate and update Row Total.
            $("[id*=lbtotal]", row).html(parseFloat(rate) * parseFloat(quantity));

            //Calculate and update Grand Total.
            var grandTotal = 0;
            $("[id*=lbtotal]").each(function () {
                grandTotal = grandTotal + parseFloat($(this).html());
            });
            $("[id*=lblGrandTotal]").html(grandTotal.toString());
        });
    });
</script>