Where Does the “There are no items to show in this view” Text Come from in a DVWP?

I got a question via email today, the answer to which seemed generally useful:

While you’re not as cool as Old Spice guy (sorry, nobody is that cool) you are the uber CQWP guy. Enough ego stroking this morning? Anyways, quick question. Any idea how to display a custom message in the CQWP when you have no items matching the filter? You can see a message in design mode but I want to set a custom message in runtime mode for users. Thought you might know off the top of your head. Thanks!

Come on, with a question worded like that, I had to post it, didn’t I?

In a DVWP, when you set the “no matching text” message in the Common Data View Tasks Common Dialog, like this

the message ends up in an XSL template called dvt_1.empty. Wouldn’t it be grand if it were something so consistent in a CQWP? I’m guessing it isn’t, but  here’s the logic from a DVWP.

In the dvt_1 template, after the nodeset is assigned to the variable $Rows, there’s a variable called $dvt_RowCount created, which contains the number of items in $Rows. Next there’s a variable called $dvt_IsEmpty, which is set to true if the value of $dvt_RowCount=0 (this part is a little needlessly verbose).  If $dvt_IsEmpty is true, then we call the template dvt_1.empty, otherwise we do the normal yadda, yadda, yadda.

<xsl:template name="dvt_1">
  <xsl:variable name="dvt_StyleName">Table</xsl:variable>
  <xsl:variable name="Rows" select="/dsQueryResponse/Rows/Row" />
  <xsl:variable name="dvt_RowCount" select="count($Rows)" />
  <xsl:variable name="dvt_IsEmpty" select="$dvt_RowCount = 0" />
    <xsl:when test="$dvt_IsEmpty">
      <xsl:call-template name="dvt_1.empty" />
      yadda, yadda, yadda

The dvt_1.empty template simply outputs the “no items here” message, like this (again, overly verbose):

<xsl:template name="dvt_1.empty">
  <xsl:variable name="dvt_ViewEmptyText">There are no items to show in this view.</xsl:variable>
  <table border="0" width="100%">
      <td class="ms-vb">
        <xsl:value-of select="$dvt_ViewEmptyText" />

Obviously, the There are no items to show in this view. message is replaced by whatever you specify. You can adapt these XSL snippets in SharePoint Designer to bend them to your will fairly easily.


  1. Actually looking into it further there are a few challenges with the problem. The Content Query Web Part is a different beast from the DVWP as everything is in bits and pieces. The items are styled in a file called ItemStyle. The main CQWP is driven by ContentQueryMain.xsl (which has an OuterTemplate.Empty template but it only displays in edit mode). So you can’t simply drop this snippet into your ItemStyle.xsl, you might have to go hunting to find the right place for it.


Have a thought or opinion?