GridView footer total doubles after sorting

Posted on 2013-09-24
Medium Priority
Last Modified: 2013-09-25
I have a basic site that pulls number from a table and calculates the totals at the foot of the table. This works well until the links to the columns are clicked to sort the table. When this is done the totals are multiplied by 2. I tried to pull the view state of the totals and push it back so it doesn't double but I'm struggling with the logic on this one. Maybe there's a better way to do it?

Code is attached. Thanks.
Question by:BigDeer
LVL 41

Accepted Solution

guru_sami earned 2000 total points
ID: 39522126
Since the GV is bound twice: first on page_load and then Sorting, the footer is calculated twice in the RowDataBound. Adjust your code like below:
protected void Page_Load(object sender, EventArgs e)
    //Call BindGridView only when it is the very first request and not on every postback
            gv.AllowSorting = true;

Open in new window


Author Closing Comment

ID: 39522147
perfect! thanks.

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Windocks is an independent port of Docker's open source to Windows.   This article introduces the use of SQL Server in containers, with integrated support of SQL Server database cloning.
An alternative to the "For XML" way of pivoting and concatenating result sets into strings, and an easy introduction to "common table expressions" (CTEs). Being someone who is always looking for alternatives to "work your data", I came across this …
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.

607 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question