Configure a DataView Web Part to display results from a centralized list regardless of site level

SP IW UA Contact: cberns@microsoft.com
Author: Rod Stagg
Title: Configure a DataView Web Part to display results from a centralized list regardless of site level
Body: by Rod Stagg SharePoint Practice Manager
LANtek Computer Services
http://www.lantekcs.com
 

Quick Tip: Using the SharePoint DataView Web Part across site collections

If you need to deploy a customized dataview Web Part (customized in SharePoint Designer) across multiple sites within a site collection, this may be a good option particularly if you want each instance of the dataview Web Part to query and render the data from a single list. 

This is useful anytime you want to store the data in a centralized location, customize the dataview web-part in SharePoint Designer, and upload to the Web Part gallery for use on any subsite. It applies to SharePoint 2010 and SharePoint 2007 and Windows SharePoint Services as well. 

Steps:

1) Convert your dataview Web Part to XSLT in SharePoint Designer.
 
2) Locate the SharePoint:SPDataSource control in code view.

3) Locate the SelectCommand section and add the webs scope to your dataview Web Part’s SelectCommand directly preceding the select query:

 
SelectCommand=”<Webs Scope=’Recursive’></Webs>&lt;View&gt;&lt;Query&gt;&lt;OrderBy&gt;&lt;FieldRef Name=&quot;Order&quot;/&gt;&lt;/OrderBy&gt;&lt;/Query&gt;&lt;/View&gt;”

 
4) Add or modify the WebUrl parameter in your <SelectParameters> section of the datasource ontolr and update the DefaultValue to {sitecollectionroot}:

 
<asp:Parameter Name=”WebUrl” DefaultValue= “{sitecollectionroot} “/>
5) Save the page, open in browser and export dataview Web Part to your computer.

6) From Site Action > Site Settings, select the link to the Web Part gallery and upload the Web Part to the Web Part gallery, or import the Web Part to any site page.

 
Exporting/Importing SharePoint webparts

 

http://office.microsoft.com/en-us/sharepoint-server-help/manage-and-share-web-parts-and-web-part-pages-HA010024106.aspx#BM4

 
Example:

 
<SharePoint:SPDataSource runat=”server” DataSourceMode=”List” SelectCommand=”<Webs Scope=’Recursive’></Webs>&lt;View&gt;&lt;Query&gt;&lt;OrderBy&gt;&lt;FieldRef Name=&quot;Order&quot;/&gt;&lt;/OrderBy&gt;&lt;/Query&gt;&lt;/View&gt;” UseInternalName=”True” IncludeHidden=”True” ID=”datasource1″><SelectParameters><asp:Parameter DefaultValue=”{listguid}” Name=”ListID”></asp:Parameter><asp:QueryStringParameter QueryStringField=”RootFolder” Name=”RootFolder” Type=”String”></asp:QueryStringParameter><asp:Parameter DefaultValue=”0″ Name=”StartRowIndex”></asp:Parameter><asp:Parameter DefaultValue=”0″ Name=”nextpagedata”></asp:Parameter><asp:Parameter DefaultValue=”100″ Name=”MaximumRows”></asp:Parameter><asp:Parameter Name=”WebUrl” DefaultValue=”{sitecollectionroot}”/> </SelectParameters><UpdateParameters><asp:Parameter DefaultValue=”{listguid}” Name=”ListID”></asp:Parameter> </UpdateParameters><InsertParameters><asp:Parameter DefaultValue=”{listguid}” Name=”ListID”></asp:Parameter> </InsertParameters><DeleteParameters><asp:Parameter DefaultValue=”{listguid}” Name=”ListID”></asp:Parameter> </DeleteParameters> </SharePoint:SPDataSource>
 
The goal for this particular use was to provide a mechanism to customize the built-in Links list as a dataview Web Part, place in the web part gallery, and be able to drop on any site page in the site collection, regardless of what sub-web and access the data in the source list, again depending on the instance, from any other specific links list located throughout the entire site collection.
 
No additional custom javascript, jquery, etc. to be maintained. I agree typically you wouldn’t scope the
webs property of the SPSiteDataQuery object to be recursive throughout the site collection but in this case the deployment is limited so it is not a detriment to performance and the webs property is supported by SharePoint. Of course there are other options, this is just one demonstrating the availability of webs property. The crosslist scope is another built-in property with it’s own uses and implementation.
 
Another option, where scoping to the specific list URL is useful, is the URL Protocol which I have used for years, more recently in conjunction with LINQ TO XML and Silverlight. This results in a much more efficient, flexible and interactive UI than can be achieved with traditional client-side scripting. Previous posts related to this topic include:
http://rstagg.wordpress.com/2009/06/18/use-sharepoint-and-silverlight-to-display-a-summary-of-sharepoint-blog-posts-on-any-site-page/.
 
Of course, with SharePoint 2010, a whole new array of options exist on the client-side OM. I found this especially usefull when my team developed an application on SharePoint 2010 Alpha at the Office 2010 Developer Kitchen at Microsoft – using the client-side OM to pull data from SharePoint MySites from WPF. Fun stuff.
http://rstagg.com/tips.aspx

Category: SharePoint 2010; Web Parts
Abstract: Quick tip on using a customized SharePoint DataView Web Part across a site collection. Useful anytime you want to store data in a centralized location. Customize the Dataview We Part in SharePoint Designer, and upload it to the Web Part gallery for use on any subsite. Applies to SharePoint 2010, SharePoint 2007, and WSS as well.

Planned Go Live: 12/2/2010
Published: 12/7/2010 11:47 AM
Byline:
Approval Status: Approved

Created at 11/22/2010 4:41 PM by
Last modified at 12/7/2010 11:58 AM by french3@msn.com
 

Advertisements