Thursday, July 7, 2011

Create three drop down levels in Sharepoint 2010 top link bar

Create three drop down levels in Sharepoint 2010 top link bar

I needed to customize the top link bar in 3
levels as follows:



You can easily do this in 2 levels through bro
wser. Customizing this for 3 levels as above diagram is tricky. This can be done without the help of Visual studio 2010, by using Sharepoint Designer. My approach is follows.
Steps:
1. You need to create a custom site map
(XML file and save in 14 ). The xml file I created look like this:




Save this file as ‘sitemap.xml’ in
Layouts. I saved this in ‘C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\LAYOUTS\TopLinkNavigation’ .
This is the datasource file for the navigati
on.

2. Open the site in sharppoint Design
er and go to V4.master page. You will find the Sharepoint menu section as follows:




Replace the SharePoint:DelegateControl……… /SharePoint:DelegateControl with your own data source. Use following code to define the datasource.

asp:XmlDataSource DataFile="/_layouts/toplinknavigation/SiteMap.xml" ID="TsetXmlDataSource" runat="server" XPath="/*/*" /


This will link the data source you created in layouts directory.

3. After CssClass="s4-tn" add the following data binding

DataBindings>
asp:MenuItemBinding Depth="0" DataMember="siteMapNode" NavigateUrlField="url" TextField="title" ToolTipField="description" ValueField="title" />

asp:MenuItemBinding Depth="1" DataMember="siteMapNode" NavigateUrlField="url" TextField="title" ToolTipField="description" ValueField="title" />
asp:MenuItemBinding Depth="2" DataMember="siteMapNode" NavigateUrlField="url" TextField="title" ToolTipField="description" ValueField="title" />


/DataBindings>
And end with /SharePoint:AspMenu>

4. Finally change the DataSourceID of SharePoint:AspMenu>
To TsetXmlDataSource

Save the changes and test the site in the browser. You may get an exception saying ‘safe control…..etc.etc’. to resolve this go to web.config change Safe=”True” in
SafeControl Assembly= "System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" Namespace="System.Web.UI.WebControls" tag.

Done.




2 comments:

  1. This comment has been removed by the author.

    ReplyDelete
  2. Actually that worked with me just by going to the master page and adding a new level in the ASP Control 'SharePoint:AspMenu':

    StaticDisplayLevels="2"
    MaximumDynamicDisplayLevels="6"


    And choosing in the Site Navigation Settings (With Publishing Infrastructure activated) to show subsites:)

    ReplyDelete