Click here to Skip to main content
15,889,877 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:

C#
decimal total = 0;
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
        total += Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "calc"));
    }
    lblTotal.Text = total.ToString();
}


What I have tried:

I am taking the sum of current page with this (I am using paging and filtering). I want all my gridview's sum and when I am filtering my gridview I want that updated too.
Posted
Updated 7-Mar-18 9:28am
Comments
Maciej Los 7-Mar-18 14:47pm    
And what's wrong with your code?
Vera Tutova 7-Mar-18 14:58pm    
I get only the current page sum. I want the total sum of my gridview. there is 5k records, and I want to sum all of them. I am using paging in gridview with 10 records. this code gives me only the current page's sum.
Maciej Los 7-Mar-18 15:20pm    
Don't you think that is bad idea to calculate sum on client side?
Think of it. You used database, true?
If yes, then you probably need such of functionality on server side (stored procedure). It should be fastest method.

1 solution

Please, read my comment to the question.

For starters i'd recommend to read this:
Tutorial 25: Efficiently Paging Through Large Amounts of Data[^]
How to: Group, Sort, and Filter Data in the DataGrid Control[^]
 
Share this answer
 

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