Monthly Archives: December 2008

“Value cannot be null” error on postback when using Grouping in SPGridView

When you use an SPGridview with grouping enabled, you will receive an exception whenever you perform a postback: Value cannot be null. Parameter name: container.

Patrick Rodgers came up with a solution which you can read here: http://www.thesug.org/blogs/patrickr/Lists/Posts/Post.aspx?ID=2

The solution is to create your own GridView that inherits from SPGridView and override LoadControlState to raise an event whenever the DataSource is null. The page or control that implement the GridView will need to implement an eventhandler and make sure the Grid is bound to it’s datasource.