• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 922
  • Last Modified:

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

Hi,
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??
Thanks!
0
arcross
Asked:
arcross
1 Solution
 
Obadiah ChristopherCommented:
Instead of rowdatabound just calculate the total after binding the gridview.

just loop around the rows of the gridview
0
 
muhammadyasirCommented:
put your calculation in

if (!Page.IsPostBack)
{

}
0
 
AmitGKCommented:
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.
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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.

 
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.
0
 
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.
0
 
Obadiah ChristopherCommented:
how ru binding the gridview
0
 
arcrossAuthor Commented:
In design time through the propery sheet.
0
 
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
0
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

Featured Post

Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now