This blog has moved to www.sharepointconfig.com

Apr17

Data View Web Part Introduction

Categories: Customisation, Data View, XSLT
This post shows how you can use the DataView web part (aka the DataFormWebPart) to display a list of items from another SharePoint 2007 site using SharePoint designer.

1. Using SharePoint designer, insert a data view web part onto the page you want to display in the list by selecting Data View > Insert Data View from the main menu.
 
2. Using the Data Source Library Task Pane in SharePoint designer select 'Connect to another library' and browse to the site that contains the list you wish to display.
 
3. Expand the new site in the Data Source Library Task Pane and select the list or library that contains the information you wish to display. From the drop down select 'Show Data' to populate the Data Preview tab.
 
4. From the list of columns, select the ones that you wish to display and select ‘Insert selected fields as… multiple item view' from the drop down menu at the top of the window. This will populate the data view with sample information (in a table by default). At this stage you may get an error in the design view that states:
 
"The server returned a non-specific error when trying to get data from the data source. Check the format and content of your query and try again. If the problem persists, contact the server administrator".
 
This can be corrected by modifying the <SelectParameters> tag of the <SharePoint:SPDataSource> element of the data view to contain the reletive url of the site for the WebUrl parameter (look at the default parameters to find this out - should be something similar to '/news/').
 
5. (Optional) Modify the XSL for the data view to display the information in the format you require. By default there is often a large amount of redundant information, and in simple cases can be replaced with the following:
<XSL>
  <xsl:stylesheet ...>
    <xsl:output method="html" indent="no"/>
    <xsl:template match="/">
      <xsl:variable name="Rows" select="/dsQueryResponse/Rows/Row"/>
      <ul>
        <xsl:for-each select="$Rows">
          <li>
            <a href="{substring-before(@URL, ', ')}"><xsl:value-of select="substring-after(@URL, ', ')"/></a>
          </li>
        </xsl:for-each>
      </ul>
    </xsl:template>
  </xsl:stylesheet>
</XSL>
 
6. Now you have the basic data coming through you can select to filter, sort, group or perform other data view related tasks by clicking on the arrow next to the data view in design view. I will cover some of these options in a later post.
 
 

Comments

On 21 Mar 2008 05:27, Dianna said:

How do I do what you described here? "This can be corrected by modifying the tag of the element of the data view to contain the reletive url of the site for the WebUrl parameter (look at the default parameters to find this out - should be something similar to '/news/')." My data source tag looks like this: Where does the relative URL go??? Please help! Dianna

On 02 May 2008 02:56, Nicholas Hadlee said:

Hi Ari, A really helpful post - just a quick question. I seem to get that error you mention in step 4 from within the designer but the page renders and the data comes trhough fine. Any idea what is causing the designer to generate the error? Cheers

On 30 May 2008 08:56, caligali said:

I am getting the error is step4, and i have this junk in the select command: selectcommand="<View></View>", every time I change it, it reverts to this.

On 09 Oct 2008 07:55, Roberto said:

If I select a document library from the dataview source, and I want to display inside the dataview documents from that document library , how can I make either the URL, Linktofile, etc column to point to the document so when the user clicks on the file the document open. I dont want the entire url to show. I only want the name of the document to be link to the file. Thanks

On 22 Apr 2009 11:54, Ayman R. Hussein said:

Thank you

On 04 May 2009 11:40, Patrick Squire said:

Hey thanks for outlining this info...Needed a few tips for a white-paper I was writing :D

On 05 May 2009 12:27, Jeremy said:

This tutorial breaks at step 4 for me. When I select a column that I want to display, the "Insert Selected Fields as..." button is grayed out.

On 07 Aug 2009 04:40, Jay Meredith said:

If you create a dataview using a custom datasouce based on a custom list, how do you update the datasource in the dataview without disturbing any custom formatting if at a later time, you add new columns to the custom list?

On 15 Oct 2009 05:19, Ari said:

This blog has been moved to SharePoint Config. To view or comment on this article please head over to Data View Web Part Introduction.

Comments for this article are now closed.