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

Analyst_SQL 3,531 Reputation points
2020-11-27T08:54:38.217+00:00

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

https://ibb.co/whrDBKD

Below is gridview and JS

43291-gv.txt

ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,254 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. XuDong Peng-MSFT 10,101 Reputation points Microsoft Vendor
    2020-11-30T02:33:00.207+00:00

    Hi @Analyst_SQL ,

    According to the code and the image you provided, I found that there are two Total columns (S.total 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