I (and others) have found a bug in ASP.NET's new GridView control. Something that worked with the old DataGrid doesn't work in the new version.
Scenario: I had to reorder my gridview's columns at runtime to support custom report views for users. I have a list of columns that the person wishes to see, and a bunch of predefined columns built into the grid using the standard declarative syntax. So, in code, I loop through the user's requested columns and find them in the grid, then move them to the end of the grid by calling myGrid.Columns.Add(theColumn) and myGrid.Columns.RemoveAt(x) methods. I then set the visible property to false for all other columns. The columns reorganize just as I want, but any columns of type TemplateField end up with blank data (actually empty control collection) when the grid is rendered. Ouch! Apparently the template column data is saved in the viewstate, but not the template column's control tree, so when you move the column, that part is lost and the grid looks empty for those columns.
Unexpected solution: I'm using the gridview's built in sorting and paging....which is awesome, and surprisingly not dependent on EnableViewstate being set to true. Turning off EnableViewstate fixed my disappearing template column stuff and the sorting and paging still magically work.
Wednesday, May 28, 2008
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment