views:

18

answers:

1

Hi

I have a really weird issue. I have a Gridview, which I bind to a Dataview programtically. My Gridview has 11 columns. Sorting works fine as long as I do not remove any columns programtically.

In certain cases I remove 2 of the columns from the Gridview. Still not a problem. All the data is properly displayed however the problem occurs when I sort one of the columns. I sort the Dataview and bind to the Gridview again. Data from two of my columns just vanishes. Both of these columns are based on ItemTemplates. The columns are still displayed but just empty cells.

Any ideas? Thanks.

A: 

Instead of removing the columns, hide them. The bound item's indexes are confused by removing the columns from the grid only and not the DataSource.

A better solution would be not to ever render those columns at all if you are always hiding them. If there are conditions to which they are removed, then hide them. CSS is an easy way to do that.

TheGeekYouNeed
I am not always hiding them. I determine programatically when to remove them. Can we programatically hide them. I'll check if that is possible. If you know then please post. Thank you.
IceFossil
Thank you. After hiding, it works fine.
IceFossil