1,804 articles and 14,766 comments as of Tuesday, April 19th, 2011

EndUserSharePoint has combined resources with NothingButSharePoint.com. You can now find End User (Mark Miller), Developer (Jeremy Thake) and IT Pro SharePoint (Joel Oleson) content all in one place!

This site is a historical archive and is no longer being updated. Please update your favorites, bookmarks and RSS feeds.

NothingButSharePoint.com
Thursday, July 8, 2010

SharePoint: Extending the DVWP – Part 17: User-Managed Dropdowns – Creating a Relationship list

Author: Jim Bob Howard

Whether working with cities and states, sizes and colors, jobs and locations, etc., the ability to cascade—or limit—the choices of one dropdown based on the selection in another is a requirement for usability.

But before we start cascading our dropdown selections, we need to consider the data that will be in each one and the relationship between them. In many cases (sizes/colors; jobs/locations), it’s also imperative that a content owner be able to modify the selections in a list. The standard choice column type isn’t the best option for this because the data is "hidden" within the column definition.

Using a lookup column makes much more sense. And that’s what we need if we’re going to cascade our dropdowns.

Note: All of the content and thought process for this article arose from a discussion with Marc Anderson in January 2010 on the discussion forums for his jQuery Library for SharePoint Web Services (SPServices). You can read the entire conversation here.

Site Columns for Cascading dropdowns

What if the dropdown option choices are managed by one group, but used by another? For example, HR may need a strict definition of job titles, but a manager may be the one who is controlling the list of employees that use that title. So, how do we "reuse" data that might be useful company-wide?

Answer: Use site columns, which I discussed in the last article in this series.

Assuming you followed the advice in the last section, of the Countries and States, you already have the two data lists. You will need the related data to be stored in the respective lists before setting up the relationships.

It’s All in the Relationships

Cascading dropdowns depend on the relationship between the data in the two dropdown lists. So, first we create a list for each of the sets of data (e.g. Countries and States); then we set up a list that describes the relationship between the two.

Let’s now set up the relationship list.

  1. Click Site Actions -> Create

  2. From main site, click Site Actions -> Create

  3. Under Custom Lists, click Custom List in Datasheet View

  4. For this example, I’m going to relate Countries and States, so I’ll name it RELCountryStates

  5. Creating the relationship list with a name that contains no spaces will help us down the road

    Notice that I don’t want this to show up in the Quick Launch (your requirements may vary).

    Give your list a name without spaces for now; this will set its ’static name.’ We’ll update the ‘display name’ in the next step.

  6. You’ll now see that we have a list in Datasheet view. Let’s modify it, then we’ll load the data. Click Settings -> List Settings

  7. RELCountryStates – Click Settings -> List Settings

    1. Change the name
      1. Under General Settings, click Title, description and navigation

      2.  Change the Name to something descriptive (e.g. Country-State Relationships)

      3. Set the ‘display name’ of the List

      4. Click the Save button
    2. Remove attachments
      1. Under General Settings, click Advanced settings

      2. Under Attachments, click Disabled

      3. Disable attachments

      4. Click the OK button (twice)
    3. Add site columns
      1. Click Add from existing site columns

      2. Click both site columns and click the Add > button

      3. If you assign your relationship site columns to a common group, they’re easy to find

      4. Leave Add to default view checked and click OK
  8. Click the list name in the breadcrumbs to return to the datasheet view

  9. The breadcrumb will take you back to the datasheet view


    Datasheet view with site columns Countries and States

  10. You will need the related data to be stored in the respective lists before setting up the relationships. If you haven’t done that already, do it now. (Last time, I shared a method for quickly loading data in the lists used by your site columns.)
  11. Now, all you need to do is add a record for every State in your site column list and relate it to its Country.

  12. The site columns now have dropdowns for selecting only from valid values.

  13. Loading these one by one will take forever, so we’re going to do something similar to what we did when we loaded the site column lists, by pasting the entire list into this table. But we’re going to have a bit of an issue with the Title column, which is required by default. Here are our options:
    1. We can make the Title optional (and hide it from view, if desired)
    2. We can make it optional and create a workflow that concatenates the site columns to make up a unique Title. (Not recommended.)
    3. We can use Excel to create our entire Country-State Relationships table and paste the entire thing in here.

Next time, I’ll show you a quick way to load the data using the first option; then I’ll walk through it using Excel.

Author: Jim Bob Howard

Jim Bob Howard is a web designer / webmaster in the healthcare industry. He has been working with SharePoint since March 2009 and enjoys sharing what he has learned. He is a moderator and frequent contributor to Stump the Panel, and answers SharePoint questions on Twitter (@jbhoward) and via email ([email protected]).

View all entries in this series: Extending the DVWP»
Entries in this series:
  1. SharePoint: Extending the DVWP - Part 1: Layout Enhancement - Rearranging Columns - Default and Edit Templates
  2. SharePoint: Extending the DVWP - Part 2: Layout Enhancement - Rearranging Columns - Insert Template
  3. SharePoint: Extending the DVWP – Part 3: Getting it All on One Line - DVWP Function Action Links
  4. SharePoint: Extending the DVWP – Part 4: Turning DVWP Action Links into Buttons
  5. SharePoint: Extending the DVWP – Part 5: Doing Stuff Before Save on Submit - PreSaveAction()
  6. SharePoint: Extending the DVWP – Part 6: Examining the Form Action Links
  7. SharePoint: Extending the DVWP – Part 7: Creating a Form Action Workflow
  8. SharePoint: Extending the DVWP – Part 8: Creating a Form Action Workflow - The After Math
  9. SharePoint: Extending the DVWP – Part 9: Oops! Failed Setting Processor Stylesheet
  10. SharePoint: Extending the DVWP – Part 10: Passing Workflow Variables to a Form Action Workflow
  11. SharePoint: Extending the DVWP – Part 11: Getting More Form Fields to the Workflow
  12. SharePoint: Extending the DVWP – Part 12: Adding More Form Fields from the Data
  13. SharePoint: Extending the DVWP – Part 13: Putting PreSaveAction() to Work – Creating Variables
  14. SharePoint: Extending the DVWP – Part 14: Putting PreSaveAction() to Work with jQuery
  15. SharePoint: Extending the DVWP – Part 15: User-Managed Dropdowns with Site Columns
  16. SharePoint: Extending the DVWP – Part 16: User-Managed Dropdowns - Loading Data
  17. SharePoint: Extending the DVWP – Part 17: User-Managed Dropdowns – Creating a Relationship list
  18. SharePoint: Extending the DVWP – Part 18: User-Managed Dropdowns – Loading the Relationship list – Part 1
  19. SharePoint: Extending the DVWP – Part 19: User-Managed Dropdowns – Loading the Relationship list – Part 2
  20. SharePoint: Extending the DVWP – Part 20: Cascading Dropdowns - Applying the jQuery
  21. SharePoint: Extending the DVWP – Part 21: Cascading Dropdowns - Three-tier Cascade
  22. SharePoint: Extending the DVWP – Part 22: Creating Title Based on Other Fields with jQuery
  23. SharePoint: Extending the DVWP – Part 23: Creating Title Based on Other Fields with a Workflow
  24. SharePoint: Extending the DVWP – Part 24: A Note to Readers
  25. SharePoint: Extending the DVWP – Part 25: Using an Audit Trail by Creating List Items with SPServices
  26. SharePoint: Extending the DVWP – Part 26: Modifying the Edit Template
  27. SharePoint: Extending the DVWP – Part 27: Adding an Alternate Edit Template to a DVWP
  28. SharePoint: Extending the DVWP – Part 28: Massage the Remove Template
  29. SharePoint: Extending the DVWP – Part 29: Modifying Form Action Workflows on the remove Template
  30. SharePoint: Extending the DVWP – Part 30: Using EasyTabs with Filtered DVWPs to Make Data Manageable
  31. SharePoint: Extending the DVWP – Part 31: Filling in Default Data on the insert Template with jQuery
  32. SharePoint: Extending the DVWP – Part 32: Filling in Default Data on the insert Template with Multiple DVWPs
  33. SharePoint: Extending the DVWP – Part 33: Modifying Total and Subtotal Row Layouts in DVWP
  34. SharePoint: Extending the DVWP – Part 34: Using Icons for Form Action Links
  35. SharePoint: Extending the DVWP – Part 35: Putting it All Together
  36. SharePoint: Extending the DVWP – Bonus: Fixing the Insert Form Action When "No Matching Items"
  37. SharePoint: Extending the DVWP – Bonus: Creating a Title Based on Dropdowns with jQuery
 

Please Join the Discussion

2 Responses to “SharePoint: Extending the DVWP – Part 17: User-Managed Dropdowns – Creating a Relationship list”
  1. Greg says:

    Hi Jim,
    I actualy tested the SPServices cacading dropdows from Marc on SP2010 just yesterday!
    Creating a 3rd ‘Relationship’ List is a great trick – however, I don’t see yet what the exact advantage of it is yet?
    The way I had done it was lookup from 1 List towards the other at the item level and then fill out the look up column in the child list with the correct lookup using the Data view.
    Can’t wait to see how you tie it with the DVWP.

    Have you tried SP2010 yet?

    Greg

Trackbacks

Check out what others are saying about this post...
  1. [...] modifications easier for the user, we’ll set up some site columns, load them with data, and create relationship lists between the site columns (and load those one of two ways). Then we’ll put those site columns [...]




Notify me of comments to this article:


Speak and you will be heard.

We check comments hourly.
If you want a pic to show with your comment, go get a gravatar!