Simon Harriyott

Saving a GridView's control state

Been trying to get the .NET 2005 GridView to "remember" the sorting and paging settings, and apply them next time a visitor returns to the site. The LoadControlState and SaveControlState methods are protected, so I derived a class from GridView, and added public methods to expose them. These are called on Page_Load and from a button event handler.

I used a BinaryFormatter to serialize and deserialize the control state Object to a file, which works quite well. Clearly this wouldn't be appropriate for real life, as it should go in the database, but it does prove the concept, which is all I need at the moment.
27 January 2005