About Me

My photo
Currently working as a Pen Tester, I'm interested in Android and web apps.

Tuesday, 17 August 2010

Populating a 'Drop Down List' from a SharePoint List

I've been playing around with SharePoint Lists and I've found a handy way of populating a drop down list in SharePoint with another SharePoint List. Here is a quick guide;

In this example I'm creating a place where a user enters their name and then selects what country they are from. So I create two Lists
  • User Details
  • Countries
User Details will have two columns; 'Name' and 'Country'.

Step 1
Create the Custom Lists
Site Actions > Create > Custom List
Add columns;

Settings > Create Column
or Settings > List Settings > Create Column


The above screen shot is of the Country column being created within the User Details List. Notice that instead of filling in a list of countries in this column I simply put 'none' in the "Type each choice on a separate line" box. I'm not listing countries here because I want to populate this from a SharePoint List that I've made called Countries.


Step 2
Now create a Document Library
Site Actions > Create > Document Library

Then create a Web Part page. Choose the layout as a full page and add it to the document library just created.

Step 3
Launch SharePoint Designer and open up the Web Part page just created.


Delete the 'click to insert Web Part' from the page and add a Custom List form to the page.
Insert > SharePoint Controls > Custom List Form...


Then select the List you want to populate, in this case it's the User Details List.

Now right click where the Country drop down is and select the following;
Format Item as > Drop Down List


Make sure the drop down list, which will now have unbound, is not selected (click beside it). Go over to the right of SharePoint Designer 2007 to the window with the tabs Toolbox, Data Source Library... etc. and click the 'Data Source Library' tab.
*If it is not there go to the top toolbar (File, Edit, View...) and click on Task Panes -> Data Source Library.

Find the List that you want to populate the drop down with, in this case the Countries list will populate the drop down. Click the list and click inset data source control.

Now go back to the drop down and click the little arrow and then click Data Fields.

A window will pop up, the first option is the data field just leave it as this is the one selected (although you can change it if you want). In this case the data field selected is Country in the User Details List.

There is also an option here to present the user with data from one column in the List and once selected by the user a value is entered from a different column in the List from a corresponding row. This is handy if you want a description for the data presented to the user but want a number value to be entered into the List.

Step 4
All that needs to be done now is to change the view the user gets when they are creating a new Item from the default view to your new Web Part page with the custom form.

Go to the Lists on the left hand side of SharePoint, expand Lists and then right click the User Details List and click Properties.



Then in list properties click the 'Supporting Files' tab and do two things

  • *Very important that under 'Content type specific forms:' you change it from 'Folder' to 'Item'.
  • Then change the 'New item form' to the Web Part page with the custom form (Pages/userdetails.aspx) by pressing browse and locating you new page.



All done. Now when a user clicks 'New Item' in SharePoint they will be brought to the Web Part page and the drop down list will be populated from another SharePoint List.

No comments:

Post a Comment