Click here to Skip to main content
14,207,783 members
Rate this:
 
Please Sign up or sign in to vote.
How to get footer total sum from ASP.NET GridView and transfer that sum in label on another page?

This is my script for get checked cell sum from column in GridView in footer :
<script type="text/javascript">
    $(function () {
        $("input[type=checkbox]").change(function () {
            var totalPrice = 0, ctlPrice;
            $('#GridView1 tr').each(function () {
                if ($(this).find('input:checkbox').attr("checked")) {
                    ctlPrice = $(this).find('[id$= lblListPrice]');
                    totalPrice += parseFloat(ctlPrice.text().replace(/[^\d\.]/g, ''));
                }
            });
            $("#<%=GridView1.ClientID %> [id*=lblTotal]").text(totalPrice.toFixed(2));
        });
    });
</script>



[Edit member="Tadit"]
Added pre tags.
[/Edit]
Posted
v3
Comments
Ankur\m/ 25-Apr-14 2:53am
   
What have you tried? Did you even search on Google for similar discussions. Please do, you won't be disappointed.
R.Elena 25-Apr-14 3:02am
   
this is my script for get checked cell sum in footer

<script type="text/javascript">
$(function () {
$("input[type=checkbox]").change(function () {
var totalPrice = 0, ctlPrice;
$('#GridView1 tr').each(function () {
if ($(this).find('input:checkbox').attr("checked")) {
ctlPrice = $(this).find('[id$= lblListPrice]');
totalPrice += parseFloat(ctlPrice.text().replace(/[^\d\.]/g, ''));
}
});
$("#<%=GridView1.ClientID %> [id*=lblTotal]").text(totalPrice.toFixed(2));
});
});
</script>

I tried on Google but I can'e find similar discussion
   
What is the issue with this code? Did you debug?
R.Elena 25-Apr-14 4:07am
   
Code is good. This code is in Page1.aspx, I want to get lblTotal value and pass it in Label on Page2.aspx
Ankur\m/ 28-Apr-14 1:34am
   
You are assigning the total text to the label. Is it not showing correctly?
And about passing the value to another page, you will need to do it on the server side. Calculate the total on OnItemDataBound event. Pass to to another page by using session or any other state management technique.
R.Elena 28-Apr-14 5:13am
   
it is show correctly in footer in lblTotal . But the value won't pass to another page :)
Ankur\m/ 28-Apr-14 6:14am
   
And how are you passing it to another page? Are you redirecting to another page through client side (using JavaScript) or through server side (Response.Redirect / Server.Transfer)?
R.Elena 28-Apr-14 7:12am
   
throught server side. Is it posible throught client side (JavaScript) and how?
Ankur\m/ 28-Apr-14 8:27am
   
There are many ways to pass the value. I have already told about one of them in my previous comment - "Calculate the total again on OnItemDataBound event. Pass that to another page by using session or any other state management technique."<br>
Yes, it can be done through client side as well. Add the value in a querystring to the url you are redirecting to. Read the querystring value in that page.
R.Elena 28-Apr-14 9:23am
   
Can you gave me a example for add label valie in query string to the url in javascript?

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

Try like below...
// Get the total Label value.
var total = $("#<%=GridView1.ClientID %> [id*=lblTotal]").text();

// Pass to Page2.aspx Page by QueryString or something according to your logic.
   
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Advertise | Privacy | Cookies | Terms of Service
Web02 | 2.8.190612.1 | Last Updated 25 Apr 2014
Copyright © CodeProject, 1999-2019
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100