Overriding the no items message in an XLV

I recently posted about how to modify the default message that is displayed in an XSLT List View Web Part when there are no items to display. In the first post I modified some default parameters in the .webpart file, but I hinted that there is a better way… Well, having been reminded by a colleague today that I hadn’t yet posted the better way – here it is!

Rather than having to modify the default parameters it is possible to use the XSL Template Override technique that I mentioned in a previous post. Using this method we can link to a simple XSL file to display whatever message we choose instead of the default no items to show in this view message.

Firstly the XSL needed – it’s extremely straight-forward – simply overriding a template called EmptyTemplate like so:

<xsl:stylesheet xmlns:x="http://www.w3.org/2001/XMLSchema" xmlns:d="http://schemas.microsoft.com/sharepoint/dsp" version="1.0" exclude-result-prefixes="xsl msxsl ddwrt" xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime" xmlns:asp="http://schemas.microsoft.com/ASPNET/20" xmlns:__designer="http://schemas.microsoft.com/WebParts/v2/DataView/designer" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:SharePoint="Microsoft.SharePoint.WebControls" xmlns:ddwrt2="urn:frontpage:internal" xmlns:o="urn:schemas-microsoft-com:office:office"> 
	<xsl:include href="/_layouts/xsl/main.xsl"/> 
	<xsl:include href="/_layouts/xsl/internal.xsl"/> 
	
	<xsl:template name="EmptyTemplate">
		<tr>
			<td class="ms-vb" colspan="99">No items</td>
		</tr>
	</xsl:template>
</xsl:stylesheet>

Now editing the XSLLink property of the web part:
XLV No Items XSLLink Property

Saving the page and we have now changed the default no items message from this:
XLV OOB No Items

To this:
XLV No Items XSL Override

I think that’s a nice simple approach to a common enough request – and one that can be re-used time and time again with the same XSL file.

share and enjoy
  • Print
  • Twitter
  • Digg
  • del.icio.us
  • StumbleUpon
  • Yahoo! Buzz
  • Google Bookmarks
  • Facebook

2 comments to Overriding the no items message in an XLV

Leave a Reply

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>