locked
Javascript code is not calculating gridview column total in textbox RRS feed

  • Question

  • User-367318540 posted

    Below is my javascript ,which is not calculating correct last column total in gridview footer and textbox which is outside gridview and i also want when i delete from gridview or change any rate then same change get update in textbox (txttotal),

    image link

    https://ibb.co/whrDBKD

    Javascript

          <script type="text/javascript">
        $(function () {
         
     
            //Calculate and update Grand Total.
            var grandTotal = 0;
            $("[id*=lbltotal]").each(function () {
                grandTotal = grandTotal + parseFloat($(this).html());
            });
            $("[id*=txtTotal]").val(grandTotal.toString());
              });
    
          </script>
                  <asp:GridView ID="GVFood"  Width="97%"  PagerStyle-CssClass="pager" HeaderStyle-CssClass="header" ShowFooter="true"
                            RowStyle-CssClass="rows"  runat="server" AutoGenerateColumns="false" auttopostback="true"
                 OnRowEditing="GVFood_RowEditing" OnRowDataBound="GVFood_RowDataBound" OnRowDeleting="GVFood_RowDeleting" 
                            Height="216px" CssClass="auto-style15" >
           
                                             <Columns>
                                                  <asp:TemplateField HeaderText="S.No">
            <ItemTemplate>
                 <%#Container.DataItemIndex+1 %>
            </ItemTemplate>
        </asp:TemplateField>
                                                  <asp:BoundField DataField="B_ID" HeaderText="Codeitem" Visible="false" />
            <asp:BoundField DataField="B_Name" HeaderText="Descriptionitem" Readonly="true" />
            <%--<asp:BoundField DataField="QTY" HeaderText="QTY" onkeyup="CalculateTotals();" ControlStyle-Width="20px"  />--%>
                                                  <asp:TemplateField HeaderText="Quantity">
                    <ItemTemplate>
                        <asp:TextBox ID="QTY" Text='<%#Eval("QTY") %>' Enabled="true"  AutoPostBack="True"  ontextchanged="QTY_TextChanged" runat="server"  ControlStyle-Width="50px" ></asp:TextBox>
    
                    </ItemTemplate>
                </asp:TemplateField>
                                                  <asp:TemplateField HeaderText="Price">
                    <ItemTemplate>
                           <asp:Textbox ID="Rate" runat="server"  Width="50px" Enabled="true"  AutoPostBack="True"  ontextchanged="Rate_TextChanged" Text='<%#Eval("Rate") %>'></asp:Textbox>
    
                    </ItemTemplate>
                                   
                </asp:TemplateField>
                                                 <asp:TemplateField HeaderText="Dis">
                    <ItemTemplate>
                           <asp:Textbox ID="txtdisc" runat="server" AutoPostBack="True"  ontextchanged="txtdisc_TextChanged"   Width="50px" Enabled="true" Text='<%#Eval("txtdisc") %>'></asp:Textbox>
    
                    </ItemTemplate>
                                   
                </asp:TemplateField>
                                                 <asp:TemplateField HeaderText="S.Total">
        <ItemTemplate>
      <asp:Label ID="lbltotalDisc" runat="server" Text=""></asp:Label>
    
        
        </ItemTemplate>
                                                      </asp:TemplateField>
    
    
    <asp:TemplateField HeaderText="Total">
        <ItemTemplate>
      <asp:Label ID="lbltotal" runat="server"   Text='<%# Eval("lbltotal") %>'></asp:Label>
    
        
        </ItemTemplate>
             <FooterTemplate>
                                            <asp:Label ID="lblGrandTotal" runat="server"></asp:Label>
                                        </FooterTemplate>
                                         </asp:TemplateField>
    
                                            
    
                                                  <asp:CommandField ShowDeleteButton="True" ButtonType="Link" />
        </Columns>
                        </asp:GridView>

    Friday, November 27, 2020 5:08 AM

Answers

  • User1535942433 posted

    Hi akhterr,

    Accroding to your description and codes,I have created a test but I don't reproduct your problem.

    I suggest you check if call the jquery twice? You could press F12 to check the result when running.

    Best regards,

    Yijing Sun

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, November 30, 2020 6:19 AM