SharePoint – How to Display Related data joined from 2 Lists in a Data View web part

Posted by: Ravi Keshwani , on 9/26/2010, in Category SharePoint
Views: 59798
Abstract: In this article, I will explain you how to display data from 2 lists, based on joins associated with it. In short, we will display master-detail records in SharePoint
Continuing my beginner series on SharePoint, in this article I will explain you how to display data from 2 lists, based on joins associated with it. In short, we will display master-detail records.
There is no coding involved for this task and can be achieved using the inbuilt mechanism provided by SharePoint. Taking a real life example, let us say we have 2 lists - Teams and Projects. ‘Projects’ are assigned to the ‘teams’ which can be one-to-many. We have to display data in a form, to display all the projects assigned team wise.
If you are not aware of how to create lists in SharePoint, please follow this article SharePoint - Creating a Lookup column in a Custom List.
Follow the below steps to implement this functionality….
Step 1: Create a list named ‘teams’ which stores team related information.
Step 2: Create a list name ‘Projects’ and add a lookup column related to the above created ‘team’ list and insert some sample data as shown below:
Step 3: Open your website in SharePoint designer and create a new page inheriting master page provided by SharePoint via File > New which will display a screen as shown below.
Step 4: Add Content Placeholders as shown below for providing the heading of the page and a PlaceHolderMain ,where our data view webpart will reside as shown below.
<asp:Content id="Content2" runat="server" contentplaceholderid="PlaceHolderPageTitleInTitleArea">
      Team Wise Project Assignments
<asp:Content ContentPlaceHolderID="PlaceHolderMain" runat="server">
Step 5: Now click on ‘Dataview Menu and select Manage Data source item from it. We have to add a linked source so click on Create a new Linked source…’ link which is placed below the Linked source drill down item, from the data source library pane.
Step 6: Clicking on ‘Create a new Linked Source…’ will open a window as shown below:
Step 7: Now click on ‘Configure Linked Source…’ button which will pop a window where you can select lists from where you want to grab linked data.
Step 8: Select ‘Projects’ and ‘Teams’ lists and click next. You should now see a window where you have to set how the data is to be grabbed from the selected lists. Select the second option ‘Join the contents…’  as shown below and click Finish.
Step 9: Now in the general tab, give appropriate name to this linked data source asTeam-Projects’ and click OK. This will add a new linked data source item in ‘Linked Data Sources’ in Data source library.
Step 10: Put the cursor on next line of ‘PlaceHolderMain’ and insert a data view web part from ‘insert-> Dataview’ menu. You will see that the current data source in the data view webpart will be the linked data source you created recently.
Step 11: Right click on the linked data source and click on ‘show data’. Select ‘Title’ field from the ‘Teams’ data source and click on ‘Insert Selected Fields as’  > Multiple Item View to insert button to insert the names of the Team in data view webpart.
Step 12: Now the data view web part will show all the team names. Place the mouse cursor on any of the row of teams, in the data view web part
And now select ‘Projects’ folder from the data source details pane and select field ‘Title’ from it. After this select ‘Insert Selected field as..’ > ‘Joined Subview’.
Step 13: The next screen will ask for the columns which are to be joined to get related data. Select ‘Title’ field from the left section and ‘Team’ Field from right section as shown below.
Step 14: Click OK and right click on the page from the ‘Folder list’ pane and click ‘Preview in browser’ option which will now show you the linked data of Projects allocated to all the teams.
That’s it! This is how you can show related data (Master-detail) in SharePoint using its inbuilt capabilities.

This article has been editorially reviewed by Suprotim Agarwal.

Absolutely Awesome Book on C# and .NET

C# and .NET have been around for a very long time, but their constant growth means there’s always more to learn.

We at DotNetCurry are very excited to announce The Absolutely Awesome Book on C# and .NET. This is a 500 pages concise technical eBook available in PDF, ePub (iPad), and Mobi (Kindle).

Organized around concepts, this Book aims to provide a concise, yet solid foundation in C# and .NET, covering C# 6.0, C# 7.0 and .NET Core, with chapters on the latest .NET Core 3.0, .NET Standard and C# 8.0 (final release) too. Use these concepts to deepen your existing knowledge of C# and .NET, to have a solid grasp of the latest in C# and .NET OR to crack your next .NET Interview.

Click here to Explore the Table of Contents or Download Sample Chapters!

What Others Are Reading!
Was this article worth reading? Share it with fellow developers too. Thanks!
Share on LinkedIn
Share on Google+

Ravi Keshwani is an MCA with 5+ years of experience in Microsoft Technologies.

Page copy protected against web site content infringement 	by Copyscape

Feedback - Leave us some adulation, criticism and everything in between!
Comment posted by Mike Lauer on Tuesday, October 19, 2010 9:44 AM
Good article, but does this apply to SharePoint 2010, 2007, or both?
Comment posted by Jacky on Thursday, December 9, 2010 10:43 AM
Thanks for the article. But in case I've two prj site, and with your article, I can link up the two prj task into one data source. But how can I display the "combined prj task" into gnatt view or similar view that Sharepoint provided when listing prj task?
Comment posted by hariprasad naidu on Tuesday, February 14, 2012 4:31 AM
i am using same your post called Display Related data joined from 2 Lists in a Data View web part.

But i am getting message in dataview webpart there are no items show in this view after i did the join sub view.
Pls help me the same.
Comment posted by Mark Lee on Sunday, October 14, 2012 8:16 PM
For those who want an add-in to easily display related content, as well as auto set and hide the parent item lookup column from children item forms, you can find it here:

Hope that helps someone else!