Changing the no items message for an XLV web part

For various reasons on my recent project I’ve been digging around the XSLT List View Web Part (XLV) and learning as much as I can about it. XLVs are very powerful and combined with SharePoint Designer 2010 pave the way for something fantastic customisations. However – not everything has to be done with SPD…

As one of my earlier posts showed, it’s possible to create an XLV that can be exported as a .webpart file and saved locally. Once you have this .webpart file then theoretically you can make all the same changes that you can in SPD. In practice, SPD is a great tool and if it weren’t for some very specific requirements on my project I’d be using that for what I’m about to show you.

So, take the scenario where you have a Document Library on a page and it’s possible that at certain times or under certain conditions (e.g. if filtered by user) there are no items to display in the web part. At which point you’ll become familiar with the “There are no items to show…” message appearing. Whilst this message is perfectly acceptable for the vast majority of cases – it’s a little too SharePoint-y and there may be times when you’d like to personalise it just a little bit more.

XLV No Items Default Message

I’ve actually found a couple of ways to do this (and I’ll blog later about what I think is the preferred way – using XSL [Update: here is the XSL approach]) but as I’ve recently posted about exporting the XLV then that’s the method I’m going to show you. 🙂

  1. Create an XLV web part for the document library that can be exported
    XLV No Items With Export Option
  2. Add the web part to a page and then immediately export it and save it locally
  3. In the .webpart file remove all properties other than ListUrl, ExportMode, and ParameterBindings
  4. Change the ParameterBindings property so that the two parameters for the no items message are no longer pointing at resource files, but are providing your new custom message
    e.g. This:

    <property name="ParameterBindings" type="string">  
    &lt;ParameterBinding Name="dvt_sortdir" Location="Postback;Connection"/&gt;
    &lt;ParameterBinding Name="dvt_sortfield" Location="Postback;Connection"/&gt;
    &lt;ParameterBinding Name="dvt_startposition" Location="Postback" DefaultValue=""/&gt;
    &lt;ParameterBinding Name="dvt_firstrow" Location="Postback;Connection"/&gt;
    &lt;ParameterBinding Name="OpenMenuKeyAccessible" Location="Resource(wss,OpenMenuKeyAccessible)" /&gt;
    &lt;ParameterBinding Name="open_menu" Location="Resource(wss,open_menu)" /&gt;
    &lt;ParameterBinding Name="select_deselect_all" Location="Resource(wss,select_deselect_all)" /&gt;
    &lt;ParameterBinding Name="idPresEnabled" Location="Resource(wss,idPresEnabled)" /&gt;
    &lt;ParameterBinding Name="NoAnnouncements" Location="Resource(wss,noitemsinview_doclibrary)" /&gt;
    &lt;ParameterBinding Name="NoAnnouncementsHowTo" Location="Resource(wss,noitemsinview_doclibrary_howto2)" /&gt;
    </property>
    

    Becomes:

    <property name="ParameterBindings" type="string">  
    &lt;ParameterBinding Name="dvt_sortdir" Location="Postback;Connection"/&gt;
    &lt;ParameterBinding Name="dvt_sortfield" Location="Postback;Connection"/&gt;
    &lt;ParameterBinding Name="dvt_startposition" Location="Postback" DefaultValue=""/&gt;
    &lt;ParameterBinding Name="dvt_firstrow" Location="Postback;Connection"/&gt;
    &lt;ParameterBinding Name="OpenMenuKeyAccessible" Location="Resource(wss,OpenMenuKeyAccessible)" /&gt;
    &lt;ParameterBinding Name="open_menu" Location="Resource(wss,open_menu)" /&gt;
    &lt;ParameterBinding Name="select_deselect_all" Location="Resource(wss,select_deselect_all)" /&gt;
    &lt;ParameterBinding Name="idPresEnabled" Location="Resource(wss,idPresEnabled)" /&gt;
    &lt;ParameterBinding Name="NoAnnouncements" Location="None" DefaultVallue="There are no HR policies to display." /&gt;
    &lt;ParameterBinding Name="NoAnnouncementsHowTo" Location="None" DefaultValue="Please come back later!" /&gt;
    </property>
    
  5. Now import the web part to a page and hey presto your custom message is now displayed!
    XLV No Items Custom Message
  6. Ok, so whilst the question of how to modify the default no items message is a legitimate one – this solution is probably not the one I’d go for. However, it does show you that changes to the XLV do not immediately mean cracking open SPD.

    For example, one other piece of work I’ve done in a similar vein is to add a new parameter to the XLV that can be populated from a filter web part. This new value is then used in custom XSL given to the web part.

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

1 comment to Changing the no items message for an XLV web part

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>