SPGridView Gotcha #2: Performance Issues / DataBinding multiple times

7 September 2012

Going off my previous SPGridView post a few days ago, I ramped up the testing for the SPGridView to grab some data from a live service hosted online somewhere. However, the performance for the SPGridView was terrible - it took somewhere within the range of 5-6 seconds to switch between pages of 10 items.

Busting out the ULS logging and debugging tools, it turns out the Select method on the ObjectDataSource was being called multiple times (nine, to be exact) instead of only the once that was necessary. After a lot of head scratching and reflector, I worked out the answer.

It turns out that by following Erik Burger's blogpost and code, by having the grid view columns set up on the Render method, by that time it was too late and the GridView was already bound to the ODS so every new column that was being added triggered a databind + select on the ODS... which if you multiply out by the number of columns in your table, makes it a pretty big performance hit.

Check out the StackOverflow question for more details (including why I don't actually even need to call DataBind() myself at all, but the moral of the story is - not everything on the internet (which includes this post) is ever going to be 100% correct all the time :)

Tags: ObjectDataSource, performance, SPGridView

Add a Comment

No Comments