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: 55179
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:
iimage_2-1
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.
mage_1-1
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>
<asp:Content ContentPlaceHolderID="PlaceHolderMain" runat="server">
</asp:Content>
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.
image_3-1
Step 6: Clicking on ‘Create a new Linked Source…’ will open a window as shown below:
image_2-1
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.
image_4
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.
26092010image_5
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.
image_1-1
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.
image_2-1
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
image_3
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’.
image_4
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.
image_5
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.
iimage_1
That’s it! This is how you can show related data (Master-detail) in SharePoint using its inbuilt capabilities.
Was this article worth reading? Share it with fellow developers too. Thanks!
Share on LinkedIn
Share on Google+
Further Reading - Articles You May Like!


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:

https://store.qipoint.com/SharePoint-Related-List-Content-Viewer-p/sp14-00-rlist.htm

Hope that helps someone else!

Categories

JOIN OUR COMMUNITY

POPULAR ARTICLES

FREE .NET MAGAZINES

Free DNC .NET Magazine

Tags

JQUERY COOKBOOK

jQuery CookBook