Javascript is calculating wrong column total in gridview ,and textbox(txttotal) outside gridview.

Analyst_SQL 3,266 Reputation points

i tried to resolve it by myself ,but it is not getting resolved below is javascript,which is i am using for calculating total of Gridview last column total but it is two column values in footer,

Second thing if i change any value in gridview ,it also must be update txttotal textbox which is outside of gridview

as you can see in image

Below is gridview and JS


ASP.NET Web Forms
ASP.NET Web Forms
A part of the ASP.NET web application framework that can be used to create ASP.NET web applications.
618 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. XuDong Peng-MSFT 6,311 Reputation points Microsoft Vendor

    Hi @Analyst_SQL ,

    According to the code and the image you provided, I found that there are two Total columns ( and Total) in the GridView.

    <asp:TemplateField HeaderText="S.Total">  
             <asp:Label ID="lbltotalDisc" runat="server" Text=""></asp:Label>  
    <asp:TemplateField HeaderText="Total">  
             <asp:Label ID="lbltotal" runat="server" Text='<%# Eval("lbltotal") %>'></asp:Label>  

    And their IDs all contain ‘lbltotal’, and the selector in javascript is $("[id*=lbltotal]"), so the data in these two columns will be summed. I think this should be the cause of the problem.

    I recommend that you could delete one of these two columns in the GridView. This will not cause confusion and will solve your current problem.

    Best regards,
    Xudong Peng

    If the answer is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments