When Would I Use a CQWP Over a DVWP?

Anyone who follows this blog or hears me speak at conferences knows that I am a *huge* fan of the Data View Web Part (DVWP).

A good friend sent me this quick question in an email today:

Content query webpart vs data view wp? When would you use content query over data view?

Here was the quick response I typed on my iPhone while waiting for a seat for dinner:

CQWPs are good if your users may need to reconfigure them over time because they can change the filtering and such in the Tool Pane. The drawback is that unless you get someone to write you new XSL to give you the styles you want, you’re stuck with what SharePoint gives you OOB. CQWPs also often deploy from environment to environment better because there’s more OOB to them.

DVWPs let you do basically anything you want by modifying them in SharePoint Designer. However, your users can’t do any reconfiguring on their own (unless they are SPD jocks). If DVWPs aren’t written intelligently, deployment *can* be a problem, but doesn’t have to be.

Because I find the DVWP so much more flexible, I usually choose it over a CQWP, but i do implement CQWPs from time to time as well.

What do you think?

Similar Posts

11 Comments

  1. I almost always favor the DVWP thanks to the flexibility of what is rendered. I’ve often wondered if I was just missing something. I like some of the query configuration tools of the CQWP, but in the end it has to present well.

  2. I would agree that the DVWP’s are more versitile, but yeah it does depend on the environment. I use CQWP’s when the governance group doesnt give anyone SharePoint Designer access, but I can still create detailed CQWP’s with some custom XSL(item, header and content query main) stylesheets with notepad(uhh), so the business can use as needed.

  3. I build a lot of data presentation type web components. I have to say that I cringe when I here CQWP. From my poing of view (branding/dev) the DVWP is all I ever need. I can easily control what it’s getting and how its displayed. When I don’t have access to SPD I go with SPservices to pull back my data.

  4. I guess I’ll play the contrarian here.

    I try to build solutions that are as reusable as possible for Intranets and Internets. So I tend to use Content Query Web Parts more often because I, or my designer, can build great looking roll ups that can be coded to support various types of data. Reusable roll ups allow for a consistent view throughout a site for common elements such as Announcements, Calendars and Publishing Pages. I can build a set of Content Query Web Parts that tie to a custom ItemStyle.xsl, drop those into the Web Part Gallery and then give clients a great out of the box feel for dropping customized, branded web parts right onto the page. They just have to worry about targeting a list and applying the proper filters.

    I usually end up with a DVWP if I’m building a more one-off solution for a specific need.

    Additionally, there is a third option here which is using your great SPServices tool tied to something like a jQuery template.

    1. Good comments, Mike, Tom, and Cory.

      Cory, I don’t take your comments as contrarian at all. This is (as are most things) an “it depends” type of decision. Reusability is a big variable. You can actually get good reusability (albeit differently) by storing your XSL for DVWPs centrally and using xsl:import to pull it in. This allows you to deploy DVWPs in many places, but change the XSL in one. It works well, and isn’t that dissimilar to the ItemStyles.xsl approach.

      M.

  5. Hi Marc,
    I’ve not been on planet SharePoint for a while… this is based on MOSS.

    In my experience I used a CQWP when I want to roll up information based on a Site Column used in lists on any number of sites (known today, or yet to be created). I use it to roll up – for instance – tasks assigned to me on any site in the Site Collection.

    Can the DVWP do this? It’s my understanding that DVWP need to know the GUID of any list.

    Ben

    1. Ben:

      Yes, the DVWP can do the same sort of rollups, by using the under-documented DataSourceMode=”CrossList”. I find that the DVWP give me far more flexibility, as well, as my filters can be really complex.

      I have posts here on my blog about the CrossList mode; just search for CrossList.

      M.

  6. Hi Marc,

    when we are talking about CQWP than it is part of the publishing features and it is not avaliable in SharePoint Foundation.
    Sometimes we forget that some of our customer only use SharePoint Foundation because this version provides all they features they need.
    SharePoint Foundation is a version that we oversee most of the time.

    If i would write a own web part that should be reusable and is based on DVWP or CQWP i prefere to use Data View Webpart because it is avaliable in SharePoint Foundation and SharePoint Server.

    DVWP is the real swiss knife in SharePoint and CQWP is the Letherman that you don’t want to carry around everyday because you need a belt pouch for that and cannot have it in your pocket. ;)

    Another option that i use, not when it comes not to rollup, but to display list data on another web is the XSLT List Viewer. This one is also quite flexible and can be made reusable. This will also provide the correct ribbon out of the box. I have a post about this on my blog.

    The answer to every SharePoint Question will always be the same: It depends. You would definitly end up using DVWP in SharePoint Foundation.

    Stefan

  7. I am having to resort to the DVWP for a cross site rollup on a custom content type as the CQWP does not display the Assigned to if the it is set to “Allow multiple selections” .. I take it all I need to do is make the appropriate DataSourceMode=”CrossList” + recursive changes.

    Is the best ( performant) solution over say using the Client Object model. Also, are there any gotchas I need be aware of.

    Daniel

    1. Daniel:

      Unfortunately, CrossList mode won’t display multi-select columns, either. I came up with a kludgy fix for it using SPServices, but it’s not my favorite approach.

      M.

  8. Marc

    Thanks very much for coming back to me on this. Much appreciated. I will step through your “Kluddgy fix” as I you’ve previously found I am running out of options.

    I did have idea whilst going away from my screen – I get the best ideas then ;-)
    That I could build a custom web part that took parameters ( content type, SC etc) and produced a tabular list similar XML output data to the CQWP.. but this is probably a bit over the top.

    Daniel

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.