question

akhterhussain-3167 avatar image
0 Votes"
akhterhussain-3167 asked XuDongPeng-MSFT answered

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

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


dotnet-aspnet-webforms
gv.txt (3.5 KiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

XuDongPeng-MSFT avatar image
0 Votes"
XuDongPeng-MSFT answered

Hi @akhterhussain-3167 ,

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.


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.