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.

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.

Post navigation

75 thoughts on “A drop-down menu, the SharePoint way”

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?

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.

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!

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.

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?

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

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!

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.

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.

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.

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.

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.

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?

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?

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

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?

First a quick answer to some of the guys that are asking about using it for one level, if you omit the part about using the group header and footer, and then on download-2.txt just copy the first part (rowview) and not the header and footer it works just fine.

Now a question. I am using the sample on a master page. I can make it work fine, but if I try to use it on sub-sites it breaks. I believe it is because the SHAREPOINT DATASOURCE is pointing at a LOCAL list, and can’t find it in the subsites. Is there any way to change the settings of the datasource so that it is available to the sub-sites???

If you build the DVWP wthin the site that contains the list, it won’t work in other sites. What you need to do is start on ANOTHER SITE in your site collection, and create from scratch a DVWP that will use the list as source.
The resulting DVWP will work on all sites in your site collection.

Thanks for your response Christophe. From what you stated in your answer, if I create a DVWP on a subsite for example, the dvwp should work accross all sites in the collection, however, when I try that, something seems to be missing:

1) I have to get the list by using the data library, and selecting the parent site, so what I can see the list.
2) When I include that list on the page, it is inmediately an XSLT Data View.
3) When I go to the XSLT to modify it, I get an error when inserting the DVT_1.Body XLST. The error states that it can’t find the variable $DVT_rowcount or something to that effect.

Apparently in the sub-site, I’m now building the list the right way. Can you point me in the right direction????

Thank you very much for sharing this, it works great!
2 questions:
-For some reason my menu doesn’t dipslay the icons at all. Any idea why that is?
-How can I change the displayed Menu Title into something else?

If i change this portion of the xsl code
serverclientid=”TwoLevelMenu”>Menu Title&lt
into
serverclientid=”TwoLevelMenu”>Something Else&lt

I too would like to know how to get the Menu Drop Down to show up in the Top Navigation Bar (next to the traditional Home tab). I tried replacing the “MenuPlaceholder” id with “PlaceHolderHorizontalNav” but it basically does nothing. Any advice would be greatly appreciated. I am not a developer.

Hello Crhistophe, Nice Work!!! thank you for sharing it!!!
I have tested it, and it works well…

I have a Question for you, I would like to make my dropdown menu looks different than the regular “site actions” menu.
¿Where in the code can I insert some graphic css styles to change its background, type and etc.?

The whole point of the post is to provide a no brainer solution that will automatically adopt the look of the site. If you need a custom look, you’re better of doing it from scratch, or with a client side script. You’ll find on the Web lots of free solutions!

I have used this trick to create a dropdown on my dashboard to pull from a list of forms in a library, creating list of hyperlinks to the forms (single-level). For the URL, I am pulling from the @LinkTitle xpath, and have made the appropriate changes to the code provided in DropDownMenu_1.text:

// Create the menuitem for each item
var title = ”;

var url = ”;

I got it all working except for the fact that when a link from the dropdown is selected, the URL for the page that opens is not complete. For example:

This gives me an invalid page. I tried doing a combination of sub-string options but that didnt work. Maybe there is somethign to be done with the DDWRT? I am at a loss here, ao any help from anyone woudl be GREATLY appreciated.

Hello Christophe, do you have an example of this in SharePoint 2010 ? I have an exact requirement and have follow your example step-by-step, however in SP2010. It didn’t work. I looked at the code and didn’t see if SP2010 would make any different to the codes, but couldn’t figure out why….if you know of a solution, please let me know. I have googles and search for an answer for days…Thanks much in advance.