Six months ago, I showed on a simple example how to reuse the default SharePoint drop-down menu. As Larry reminded me, it’s time for me to keep the promises I made and share more advanced solutions.
The solution I am going to detail adds two features:
- two levels instead of one
- the menu items are pulled from a SharePoint list
Visit my SharePoint site for a live demo.
There are various ways to pull content from a SharePoint list. I have chosen to use SharePoint Designer and the Data View Web Part for this example, as it is very convenient when working with grouped items.
Step 1: building the list
Here again you have various options, my preferred choice is to start from scratch and use a custom list.
We’ll need the following columns:
- Title: for the item title
- Description: text column
- Link: a text column for the hyperlink
- Icon: a text column for the link to the item icon
- Category: a column that we’ll use for grouping items.
An example from the above picture:
- Title: Cleverworkarounds – Welcome
- Description: Authority: 27
- Link: http://www.cleverworkarounds.com/
- Icon: /Utilities/Technorati.gif
- Category: Authority: 25 to 29
As you can see, a text column is more flexible than a hyperlink column to enter URLs. In the above example, I used a relative path for the icon.
Apply the sorting and filtering rules you need, don’t use grouping options at this point. For my example I applied:
1/ Sort by Category (descending)
2/ Sort by Description (descending)
3/ Sort by Title
Step 2: building the Data View Web Part
If you are not familiar with SPD and the DVWP, I recommend that you start with these references. Note in particular the tip about creating a temporary page.
So let’s create a new Web Part page and add our list. Then open the page in SharePoint Designer in design mode, right click on the list view and select “Convert to XSLT Data View” (again, see these references for details).
In Data view, select the “Common Data View Tasks” pane for the last adjustments.

We are now going to add the grouping rule. Under “Sort and Group”, select the Category field, and check the following boxes: “Show group header” and “Show group footer”.

Make other changes as needed in the “Common Data View Tasks” pane. For example, I chose to display all items (Paging option).
Our last action in design mode is to select all the column headers and delete them.
Step 3: Adding the code
We’ll now switch to code view to go through the XSLT and make some changes. Note that you can also do this directly through the SharePoint UI.
Update [01/21/09]: because of formatting issues, I have moved the code to the download section of my demo site. Right click on DropDownMenu-1.txt and DropDownMenu-2.txt to download the files.
Search for:
<xsl:call-template name="dvt_1.body"> <xsl:with-param name="ParentPath" /> <xsl:with-param name="Rows" select="$Rows" /> <xsl:with-param name="FirstRow" select="1" /> <xsl:with-param name="LastRow" select="$dvt_RowCount" /> </xsl:call-template>
And replace it with the content of DropDownMenu-1.txt.
Then search for these three templates:
<xsl:template name="dvt_1.rowview"> ... </xsl:template> <xsl:template name="dvt_1.groupheader0"> ... </xsl:template> <xsl:template name="dvt_1.groupfooter0"> ... </xsl:template>
And replace them with the content of DropDownMenu-2.txt.
Save your changes and open the page in your browser. You should now see your SharePoint list displayed in the form of a two-level drop-down menu (the SPD design view will not render the menu).
Change the value of the largeIconMode attribute from “true” to “false” if you prefer the small version.
Your drop-down menu will work as is, but you can do some additional cleanup in the XSLT and remove useless stuff.
This post is largely inspired by Tariq’s menu for SharePoint 2003 (in particular the idea to use the group footer). The 2007 version works in both Internet Explorer and Firefox.


52 comments
Comments feed for this article
January 16, 2009 at 2:16 am
larry
Great work! So hear is another question. slightly off topic. I need to create a table of contents. three columns no more than 20-30 items in a column. I want to populate this from a list and use the columns. What I am tring to do is publish infopath forms to a form library. create a webpart page and load the view to this library with just the Name(linked to item) displaying. I know this much can be done, but the list would be 1 column and will become to long to be useful. if I create multiple columns dynamically I want to calculate something like NumRows/3 and column1 first group (1-20) column2 second group (21-40) and last column the remaining items. Also when item are added or removed from the library I want the TOC to update with that.
I know I could probably create 3 different views, but I want to a void that
Can something like this be achieved?
January 21, 2009 at 10:25 am
Mike Walsh
Why, when I copy these statements into SPD 2007 is the final
strMenu += ”;
always replaced by only
strMenu += ”;
(leading of course to problems ..)
?
The only way I can get these in is to go in the browser to the XSLT editor there.
January 21, 2009 at 10:44 am
Christophe
Mike, let me double check my scripts.
Has anybody else tried it using SPD (not the browser interface)?
January 21, 2009 at 11:26 am
Christophe
I think I see what’s going on. All the brackets inside strMenu should be escaped (< and >), but my blog editor has translated them. Let me try and fix that…
January 21, 2009 at 1:01 pm
Christophe
I have moved the scripts to text files on my demo site, let me know how it goes. I did a quick test and it looks OK:
http://www.pathtosharepoint.com/Pages/TestTwoLevelMenu.aspx
January 23, 2009 at 6:48 pm
Zack
Another awesome post! Just discovered your blog about two weeks ago, and I’ve used a good chunk of your tips & tricks (mini calendar, expand/collapse buttons, among others).
This article here, I’ve been searching for something like this for awhile… although, one question… any ideas how to get a menu like this in the navigation bar at the top of the page (using this or something else)? I’m currently using the Headings and Links available in the Navigation options to link to files, and I’d prefer to have subheadings/categories in them, right now they’re all just thrown in there…
Anyway, again, great site full of great resources! Can’t wait to see what you have planned next.
January 24, 2009 at 12:38 am
Christophe
Thanks Zack
In the code you’ll find this line:
x = document.getElementById(‘MenuPlaceholder’);
“MenuPlaceholder” is the element I create in the page to host the menu.
You can use an existing element instead. As an example, I have used ‘GlobalTitleAreaImage’ on my demo page:
http://www.pathtosharepoint.com/default.aspx
The menu is now displayed in the top left corner.
In your experiments, be careful not to overwrite a key control of your page…
January 27, 2009 at 3:23 pm
SharePoint Links and Resources « Steve Mullen’s Blog
[...] Path to SharePoint – A drop-down menu, the SharePoint way. How to build two-level drop-down [...]
January 28, 2009 at 3:27 pm
Adam
Christophe,
Another great post! Is there any way to call the menu items from a list without using SPD (our IT department won’t let us loose with that here!). Not too worried at this stage about the sub-menus. I’ve implemented your simple list, which is fantastic. Setting that up to call from a list would be the icing on the cake!
Cheers,
Adam
January 29, 2009 at 1:42 am
Christophe
Adam: then you need to find another way to pull the data. Three suggestions:
- URL protocol (see my example of random quote). Doesn’t work with anonymous access.
- Web services
- JavaScript
You’ll find some references here:
http://pathtosharepoint.wordpress.com/2008/11/03/no-assembly-required/
For a one level menu, maybe the “HTML calculated column” could work too… Let me think about it!
January 30, 2009 at 3:26 pm
Adam
Christophe,
Thanks for the reply. I’ll give it some more thought! In the meantime, my simple workaround is to use the “I need to…” webpart to create my menu dropdown. It doesn’t give me the option to add an icon or a description (or a second level) to the menu, but it is a relatively simple way of creating a dropdown menu from a list.
I got the idea from Nicola Young’s post on EndUserSharepoint (http://www.endusersharepoint.com/?p=1259).
Cheers,
Adam
January 30, 2009 at 7:00 pm
Anonymous
Can you use some sort of grouping in the “I need to…” list. That might be a workaround for multiple levels.
January 31, 2009 at 4:46 am
Christophe
Adam: Nicola’s post is definitely worth a good look. It’ll only work if you have MOSS though.
April 21, 2009 at 7:58 pm
Anonymous
Do you have an example of creating a multi level menu that pulls from a list without using SharePoint Designer?
April 23, 2009 at 8:06 pm
Brooke
Great menu! Question: Can I put more than one of these drop downs on the same page? I’ve tried dropping a webpart connected to a different list on the page, then following your steps, but I get some very odd results (the original menu displays the data from the new one, and the new one displays nothing). Any thoughts as to what I am doing wrong?
Thanks,
Brooke
April 24, 2009 at 1:55 am
Christophe
Brooke: if you look at the code, you’ll see that the elements are assigned ids, for example id=”MenuPlaceholder”.
If you create several menus, you’ll need to assign different ids (for example MenuPlaceholder1 and MenuPlaceholder2, etc.).
April 27, 2009 at 12:46 am
Brooke
Doesn’t work for me. I’ve tried re-naming all the variables in the java as well, for the second menu.
I appreciate any thoughts you can give this.
Brooke
May 29, 2009 at 7:09 pm
Alen
Hi Chris,
Thanks for the code as it worked perfectly for what I needed. I was wondering if it is possible to put 2 or more multi-level drop down lists on the same page? Everytime I add another multi-level drop down and change the code to display, it breaks the first drop-down list added. Please let me know if I am doing something wrong!
Thank!
May 29, 2009 at 7:50 pm
Alen
Further, when I change the element from “Menuplaceholder” to “menuplaceholder1″ for list 1, “Menuplaceholder2″ for list 2, etc.
When you highlight any of the menu’s, the rest drop down with same list. I have changed the element id also for “TwoLevelMenuMain” to “TwoLevelMenuMain1″ and “TwoLevelMenuMain2″ for the new lists and still having the same issue.
June 2, 2009 at 3:08 pm
Christophe
Alen, there are several element ids in the script, you’ll need to check all of them to avoid duplicates. For example, replace all occurences of “Menu” with “Menu2″.
June 10, 2009 at 11:53 pm
Alen
Thanks Chris, I was able to finally resolve the issue. I had to rename only 2 elements for each separate drop down. Thanks for the code and the help!
June 2, 2009 at 7:26 pm
Debbie
Was able to get 2 instances of menu working on the same page. The second menu displays a white box over the menu title. Any ideas how to clear the white box?
November 11, 2009 at 3:07 pm
eSam
Hi Debbie,
Not sure if you ever got a response to this – and my reply is so tardy, it might be irrelevant. But I thought I would respond anyway for the benefit of anyone else facing this issue.
The fix was rather easy. Replace all the “>” and “<” characters in the javascript portion of the code with “” respectively. (i.e. the section that writes the menu contents.
That should fix the issue.
Sam
November 11, 2009 at 3:09 pm
eSam
…oops… it appears my text got stripped of code. the characters to replace are ” & g t ” and ” & l t ” (withuot the spaces) replace with “>” and “<” respectively.
June 15, 2009 at 5:48 am
David Townsend
Thanks for this awesome tutorial, and I have had great success using this menu on individual pages.
However, I want to integrate this menu into the entire site, which I assume would be done by inserting it into the default.master file. However, when i have tried to do this, it hasn’t worked.
Is there a better way of doing it?
Thanks!
Dave
July 21, 2009 at 10:41 pm
Hung
having some issue implementing the process.
Getting
Unable to display this Web Part. To troubleshoot the problem, open this Web page in a Windows SharePoint Services-compatible HTML editor such as Microsoft Office SharePoint Designer. If the problem persists, contact your Web server administrator.
July 24, 2009 at 12:44 pm
KFL
Hi,
Maybe someone can help me
- I have created a dropdown menu in MOSS 2007, but I can’t expand the menu, because i use Office 2003… do any of you guys know if there’s a plugin or something available out there…
Thanks…
November 6, 2009 at 5:45 pm
Kris
I am getting the following result :: Unable to displat this Web Part.
I copy pasted everything and going to revert back to my original version but this is odd… I followed everything to a T.
Made my DVWP, organized it accordingly with my list items. Which came out ok… kind of bland.
Still in SPD I goto code section Ctrl+F (items above) Highlight from xml open to close and insert new code…
I did notice a pop up saying something about IE6 (In IE6 the tag cannot contain a tag ??
I am assuming that I didn’t goto the end of the XML close / ?
November 7, 2009 at 2:15 pm
Christophe
Kris, double check that you did the copy/paste correctly, you may have inadvertently deleted more than needed.
November 9, 2009 at 5:07 pm
Kris
Christophe,
Thanks for your prompt response!
Quick question what are the doctype and secondary schema you are using? I am thinking this is where my problem may be??? Mine is xhtmal trans/ie6
Here is the snippet right before I would change it ::
(took the first
xsl:with-param name=”Rows” select=”$Rows” />
xsl:with-param name=”FirstRow” select=”1″ />
xsl:with-param name=”LastRow” select=”$dvt_RowCount” />
/xsl:call-template>
/TABLE>/td>/tr>
/TABLE>
/xsl:otherwise>
When I replace the area between xsl:call-template to the close /
I get the error…
Going back through and reading I see this::
“Our last action in design mode is to select all the column headers and delete them.” ???
I think I over looked this area… what do you mean delete them? Clicking and deleting each heading?I tried through the Common Data View Tasks and it does not allow all to be deleted.
November 11, 2009 at 6:14 pm
Tim
I can’t open your download docs. I right clicked and saved as target but when I went to open them they were blank.
November 22, 2009 at 10:51 am
Adrien
Just want I wanted – new to Sharepoint and thought they would have stuff like this!!! Got everything working except that when I view the page I can see the column headings. I’ve worked through the instructions lots of times and always the column headings are displayed but can’t see where I’m making the error – can any one help?
Also I want to expand the navigation to at least 4 levels – can this be done easily? If so, is there anything to watch out for.
November 22, 2009 at 11:24 am
Christophe
Adrien, I think you missed one small step in design mode:
“Our last action in design mode is to select all the column headers and delete them.”
The technique should work for 4 levels, but I haven’t tried myself.
November 23, 2009 at 9:31 am
Adrien
Thanks for the quick response. Didn’t realise it was a matter of just deleting them in SPD. All okay now.
November 30, 2009 at 9:07 am
Phoeni
Hello Christophe,
Is there a way to filter the SharePoint list data display (as links in the menu) based on the SharePoint group to which the logged-in user belongs? If yes, would you please help me with this solution?
Thanks in advance,
Phoeni
January 20, 2010 at 11:01 pm
Anthony
Christophe,
Great post!
Is there a way to NOT open a new window when clicking on the link in the pull down?
Please advise.
Thanks very much.
January 21, 2010 at 12:38 am
Anthony
Never mind. I finally figured it out.
In the XSL editor, change:
onMenuClick=”javascript:window.open(\”+ url +’\')”
to:
onMenuClick=”javascript:window.location.href=(\”+ url +’\')”
Thanks again for a great write up.
January 25, 2010 at 12:51 am
WillieJ
Christophe, thank you for your posts!
2-Things..
First, how do I get this to work with just ONE LEVEL? I have used your ‘simple example’ successfully, but really need to populate it from a SharePoint List (like in this example) – but I don’t require the 2nd level.
Second, Anthony’s suggestion above to get the link to open in the same window didn’t work for me – can you provide the code snippet for that as well?
Thanks
January 28, 2010 at 1:15 pm
Christophe
Anthony’s suggestion should work: replace window.open with window.location.href.
I have another post with a one level menu, you’ll need to try and combine both to get your result!
February 9, 2010 at 4:06 pm
Douglas Golden
This is a great help Christophe! I’ve been lurking for a while, and have used a number of your solutions. Thanks!
Unfortunately, Anthony’s suggestion isn’t working for me either. Is there something else that needs to change beside the code? The link still opens in a new page. Any other suggestions? Thanks!
February 17, 2010 at 5:25 pm
Jeannie
Is there a way to easily copy and paste the webpart into multiple pages. I’ve tried to do this, but it doesn’t show up on the new pages when copied.
February 20, 2010 at 7:22 am
Christophe
Jeannie, I’d recommend that you start here:
http://blog.pathtosharepoint.com/2009/02/15/a-content-editor-web-part-for-every-home/
More than a method, it shows a best practice when the need is to reuse the same content across multiple pages.
February 19, 2010 at 3:30 pm
WillieJ
Christophe, thank you for your posts!
I still need help with this. How do I get this to work with just ONE LEVEL?
I have used your ’simple example’ successfully, but really need to populate it from a SharePoint List (like in this example) – but I don’t need the 2nd level.
You suggested I try and combine your two solutions into one – I have failed. Will you combine them into one please?
February 20, 2010 at 7:23 am
Christophe
Willie, I am available to work on specific requests, feel free to send me an e-mail at christophe@pathtosharepoint.com.
April 6, 2010 at 6:54 pm
Anonymous
How would I put a third level or sub cat. in the drop down list so that I can split if off different areas.
June 4, 2010 at 4:23 am
Christophe
You would start by adding a level of grouping, and things would be even more complicated…
May 24, 2010 at 7:04 pm
Joanna
Like Jeannie, I am trying to apply this webpart across multiple pages. I took a look at this article, but I am still having trouble figuring out how the code should look in the .txt file: http://blog.pathtosharepoint.com/2009/02/15/a-content-editor-web-part-for-every-home/
June 4, 2010 at 4:30 am
Christophe
@Jeannie and Joanna:
Jeannie, I just read Joanna’s comment and realized I sent you on the wrong path. Sorry for that.
Once you have your Web Part, use the export option to save it to your local drive. You can then reuse it on other pages of your site by using the import option. For more information on export/import, see the Microsoft help.
The article I pointed to is a completely different approach for sharing menus across sites and site collections.
June 14, 2010 at 5:19 pm
Joanna
Thank you, Christophe! Your blog has been a great help and inspiration to me.
On another note, how do you add icons to the categories (primary dropdown), as opposed to the submenus?
July 19, 2010 at 5:53 am
Krutika
I am unable to download the code from your site.
August 26, 2010 at 5:10 pm
Ricky
Hello,
I am working with SharePoint 2010 and I can follow your instructions till I reach the part to replace the content. I cannot find line in the XSLT file. Have you got a SharePoint 2010 version of your script?
Thanks for all the great work you are doing.
August 27, 2010 at 3:56 am
Christophe
Sorry Ricky, the code is for SP 2007 only.