If you the data view web part is one of your tools, you might come across the need to embed a DVWP into a master page. You can do that as long as you make the DVWP reusable all over the site collection if we talking about a DVWP that fetch content from a list at one of the sites in the collection. However, the downside doing that, is that the DVWP will give a lot of extra markup, HTML and XSLT in your master page. Dealing with that makes the master page be a bit harder for further development and for maintain. Optionally you can looking into use a Content Editor in the master page where you link it to a text file containing your DVWP.

However, if you have created a DVWP and just want to include a single reference line link an include file in the master page to the DVWP instead of having the DVWP direct in your master page you can do that with help of Visual Studio. It’s just to create a User Control (UC) and host the DVWP in the UC file and deploy the file to SharePoint file system. When you do that it’s just to include the UC as an include file in the master page.

In the example I’ve created a link list named TopLinkList in the root site of the site collection with one extra column named SortOrder by the type choice where I have set the value 1 up to 5. The idea behind this is to include a set of links from the list in the master page that displays in the header of the pages.

LinkList1

Let’s try this out!

  1. Create the TopLinkList list and the extra column as described above and create let’s say three Items in this list
  2. Create a DVWP and the HTML & CSS that reads and display the list items. Don’t forget to make the DVWP available to all sites in the site collection. You can download my example and use it as an starting point for your further development. See the link at the end of the post
  3. Open your developer environment where you got SharePoint and in this example Visual Studio 2010 installed
  4. Open VS 2010 and create a new project by the type ’Empty SharePoint Project’
  5. Give it the name CustomTopLinks and click OK
  6. Select Deploy as a farm solution and click Finish
  7. In the solution explorer, right click at the project and select Add and then New Item
  8. Select User Control
  9. Name it TopLinks.ascx and click the button Add
  10. Copy the code from the DVWP and paste this just below the register tags and save the page
  11. In the solution explorer, right click at the project and select Build
  12. In the solution explorer, right click at the project and select Deploy. Verify that you got no errors
  13. When this is done, open your custom master page with SharePoint Designer
  14. Add the following register tag at the top of the page:
    <%@ Register TagPrefix="CustomTopLinks" TagName="CustomTopLinks" Src="~/_controltemplates/CustomTopLinks/TopLinks.ascx" %>
    
  15. Add the control somewhere in your markup where you like it to appear in the pages:
    <CustomTopLinks:CustomTopLinks id="CustomTopLinks" runat="server"/>
    
  16. Done!

Download the DVWP taken from this example

Take a look at the following image that shows the columns you’ll need

LinkList2

</ Christian>

Advertisements