SharePoint Config

Ari Bakker's thoughts on customising and configuring SharePoint

Data View Web Part Introduction

with 12 comments

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.

data-view-web-part-insert

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.

sharepoint-designer-data-source-library sharepoint-designer-connect-external-library

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.

sharepoint-designer-show-data

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”.

sharepoint-designer-data-view-non-specific-error

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/’).

data-view-web-part-data-source-weburl

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.

Post to Twitter Post to Delicious Post to Digg Post to Reddit Post to StumbleUpon

Written by Ari Bakker

April 16th, 2007 at 10:37 pm

12 Responses to 'Data View Web Part Introduction'

Subscribe to comments with RSS or TrackBack to 'Data View Web Part Introduction'.

  1. 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

    Roberto

    9 Oct 08 at 6:55 am

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

    caligali

    29 May 08 at 8:56 pm

  3. 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

    Nicholas Hadlee

    2 May 08 at 2:56 am

  4. How do I do what you described here?
    "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/')."

    My data source tag looks like this:
    <SharePoint:SPDataSource runat="server" DataSourceMode="List" UseInternalName="true" selectcommand="<View></View>" id="Whats_x0020_New_x0020_Links1"><SelectParameters><WebPartPages:DataFormParameter Name="ListID" ParameterKey="ListID" PropertyName="ParameterValues" DefaultValue="011B23AC-BBC2-4003-AA81-83DABF0756D2"/></SelectParameters><DeleteParameters><WebPartPages:DataFormParameter Name="ListID" ParameterKey="ListID" PropertyName="ParameterValues" DefaultValue="011B23AC-BBC2-4003-AA81-83DABF0756D2"/></DeleteParameters><UpdateParameters><WebPartPages:DataFormParameter Name="ListID" ParameterKey="ListID" PropertyName="ParameterValues" DefaultValue="011B23AC-BBC2-4003-AA81-83DABF0756D2"/></UpdateParameters><InsertParameters><WebPartPages:DataFormParameter Name="ListID" ParameterKey="ListID" PropertyName="ParameterValues" DefaultValue="011B23AC-BBC2-4003-AA81-83DABF0756D2"/></InsertParameters></SharePoint:SPDataSource>

    Where does the relative URL go??? Please help!

    Dianna

    Dianna

    20 Mar 08 at 4:27 pm

  5. 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?

    Jay Meredith

    6 Aug 09 at 4:40 pm

  6. 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.

    Jeremy

    5 May 09 at 12:27 am

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

    Patrick Squire

    4 May 09 at 11:40 am

  8. Thank you

    Ayman R. Hussein

    22 Apr 09 at 11:54 am

  9. This is real great info, and i share the same question raised above.
    How can you include a URL link to the related document or list item?
    Creating the dataview is good but would like to provide a link back to the document from the Title name.
    cheers

    Team Manager

    25 Nov 09 at 12:04 am

  10. I want to fix the count of row at the bottom of the web part , how do i implemtnt that ? pls help , thanks in advance

    Vivek

    25 Nov 09 at 7:44 am

  11. I have read in different articles to change ListId to ListName to avoid any problem in deployng DVWP to any other system. My problem is that i am using a list of another site in my DVWP. Basically the list in on root site while the page on which it is using via DVWP is on a subsite 2 levels below from root site. So i think only changing ListID to ListName will not be enough.

    Can you tell me how to configure my new DVWP so that it can be deployed on other system where there will be list of same name on root site?

    mohsin

    26 Dec 09 at 7:39 am

  12. @mohsin yes you will need to also add in a WebURL parameter for your data source – if you follow the steps above this will allow you to target a specific subsite.

    Ari Bakker

    2 Mar 10 at 5:20 pm

Leave a Reply