A question recently came up on Stack Overflow about querying data from multiple SharePoint lists and binding the results to a GridView control. I realised there were some types of SharePoint queries I hadn’t explored, and that it would be interesting to compare them and see how they work in a web part.
Hence, I created the SPQueryDemo web part! It tests and displays results from the following types of queries:
- For loop
- GetListItems from Lists web service
- SPQuery for SPList objects
- SPSiteDataQuery for cross-site list queries
- CrossListQueryInfo for cached cross-site list queries
- PortalSiteMapProvider for SharePoint Server publishing sites only
I’ve also used this project to try out using user controls for output rather than the traditional dynamic creation of controls in a SharePoint web part. This has been attempted with an MVP-style pattern which I’d really appreciate any feedback on.
In the future I’d like to add more functionality, particularly for different query options and types of queries. There is also an annoying bug when changing the query type where the page needs to be refreshed before changes take affect. If anyone would like to help or just check out the code, please download the source and hack away! You can also contact me via this blog post or via Twitter.