Click here to Skip to main content
15,884,986 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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 :
JavaScript
<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
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)?

1 solution

Try like below...
JavaScript
// 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.
 
Share this answer
 
v2

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900