Thursday, September 18, 2008

Customizing the content query web part (CQWP)

This is a pretty simple one, but people tend to ask about it a lot. One of the most powerful Web Parts built in to MOSS is the Content Query Web Part (affectionately known as the CQWP). This Web Part allows you to roll up content from any and all lists in the current site and all subsites and display in a custom format. If you have never played with it, you should go try it out. You can specify a content type to pull from multiple lists, sort, filter etc...

The greatest thing about the CQWP is that the data comes back as XML and gets displayed using the XSLT in the Style Library (ItemStyle), you can modify this XSLT or point it at your own file to pretty much roll up data in any way you need. This is a great solution to any client that wants you to "write us a web part to display some list data" because it is already written for you and the performance (even when accessing large lists) is pretty much as good as it gets (check out http://go.microsoft.com/fwlink/?LinkId=95450&clcid=0x409 for reference).

The one thing to remember to do is include your custom list columns in the CQWP properties via the .webpart file. There are some good tutorials on doing this (and other property customizations) from MSDN and on Heather Solomon's blog.

No comments: