Hiding/Showing columns in grdiview, at run time, causing RowDataBound event firing

Ive got a gridview showing some totals at the footer of it. The totals are calculated in the RowDataBound event.
Depending on some conditions, Im showing or hiding some columns in the grid at run time. When this happens (showing or hiding) the RowDataBound event is triggering again causing the totals to calculate twice and showing double the amount.

Me.gv_data.Columns(0).Visible = True   '// Edit column
Me.gv_data.Columns(1).Visible = True  '// Delete column

How can I stop that event for triggering when I hide a column??
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Obadiah ChristopherCommented:
Instead of rowdatabound just calculate the total after binding the gridview.

just loop around the rows of the gridview
put your calculation in

if (!Page.IsPostBack)

Shift the code for computing grid footer totals to a subroutine/function and then invoke it after you show/hide columns based on various conditions of the grid.
JavaScript Best Practices

Save hours in development time and avoid common mistakes by learning the best practices to use for JavaScript.

arcrossAuthor Commented:
Thanks for your answers....

Moving the code to another procedure of function would cause me a lot of trouble. I was wondering if there was another way to hide or show columns or to stop the user to click it depending on certain condition.
arcrossAuthor Commented:
Also, I have to add that it only happens when the page opens. If I change the date in a calendar, that ive got in the same page and it goes though the same checking routine, it is fine. The totals are correct and the hide and show works. It is just the when the page loads.
Obadiah ChristopherCommented:
how ru binding the gridview
arcrossAuthor Commented:
In design time through the propery sheet.
arcrossAuthor Commented:
I ended hiding and showing the columns in the RowDataBound event itself...

e.row.cells(0).visible = false
e.row.cells(1).visible = false

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.