Sunday, January 26, 2014

Merge Two List

How to Link Two Lists and Create a Combined View in SharePoint 2010




Item is currently unrated. Press SHIFT+ENTER to rate this item.1 star selected. Press SHIFT+ENTER to submit. Press TAB to increase rating. Press SHIFT+ESCAPE to leave rating submit mode.2 stars selected. Press SHIFT+ENTER to submit. Press TAB to increase rating. Press SHIFT+TAB to decrease rating. Press SHIFT+ESCAPE to leave rating submit mode.3 stars selected. Press SHIFT+ENTER to submit. Press TAB to increase rating. Press SHIFT+TAB to decrease rating. Press SHIFT+ESCAPE to leave rating submit mode.4 stars selected. Press SHIFT+ENTER to submit. Press TAB to increase rating. Press SHIFT+TAB to decrease rating. Press SHIFT+ESCAPE to leave rating submit mode.5 stars selected. Press SHIFT+ENTER to submit. Press SHIFT+TAB to decrease rating. Press SHIFT+ESCAPE to leave rating submit mode.


Categories:SharePoint Designer; Libraries and Lists; Views; Site Manager/Power User; MOSS; WSS; 2010



You may also be interested in: the only cloud-based Dev/Test solution for SharePoint by CloudShare


Editor's note: Contributor Melick Rajee Baranasooriya is a Senior Software Engineer at IronOne Technologies. Follow him @MelickRajee
The following steps will allow you to join multiple listd together and create a combined view. For example, assume that you are managing a list for some events. You also have a separate participants list. Now you want to join the two lists and create a composite view.
SharePoint 2010 allows you to create this kind of view using Linked Data Source. With this approach you can create your own custom list in SharePoint.

How to Create a Linked Data source

Go to SharePoint Designer and go to the link called data sources.
2012-05-10-CombineView-01.png
Click the Linked Data Source button in the ribbon. SharePoint designer will prompt the following dialog.
Add the two lists that you want linked together.
2012-05-10-CombineView-02.png
2012-05-10-CombineView-03.png
I'm adding airline schedule and booking list. These are the two lists that I want to merge. Click next and it will guide you to another screen. You will be asked to select either
  • Merge
    • Merge is used to combine lists which have the same column definitions. For example we can say this is like a Union operation in the database.
  • Join
    • Join operation is used to link two or more lists. The lists do not need to have the same column definition. This is equal to join operation in the database.
I need to join the two lists to get the passengers for a particular schedule. I will use the join option and click finish.
2012-05-10-CombineView-04.png
Then switch to the general tab and give a name to identify the data source.
2012-05-10-CombineView-05.png
Now you are done with the linked data source.

How to create a custom view using linked data source in the SharePoint designer

I'm going to create a custom aspx in SharePoint Designer and create a view for it. Go to Site Pages and create new aspx file.
2012-05-10-CombineView-06.png
In Designer you can now see an empty aspc file.
2012-05-10-CombineView-07.png
You can now add the data source into the page. There are many ways to do this. The best choice is to Insert and then select your data source to add to the page. I've found that it is not always visible in the data source task pane so you you will have to go to Data View and add your data source.
2012-05-10-CombineView-08.png
This action will generate a table in the page. But we don't need it so we'll delete it. We will want the data source in the data source task pane. (Select all and press delete on the key board.)
2012-05-10-CombineView-09.png
Go to the task data source pane and select the columns you want to add to the page. Click add as a multiple view item.
style="text-align: center">2012-05-10-CombineView-10.png
This will generate a table for you. Click the right most column, go to table and add a new column to the right as seen below.
2012-05-10-CombineView-11.png
Now, place the mouse cursor to the column and select the second list in the data source pane and select the columns you want and click Join Sub View.
2012-05-10-CombineView-12.png
Then it will ask for the relation between columns to Join (like foreign key). Here link data using ID of the Airline Schedule.
2012-05-10-CombineView-13.png
Note: Sometimes the Join Sub view will not appear. In order to see it, click two or more columns. I don't know why this occurs but it has happened to me several times. And this is how I managed to solve the problem.
Now you can see a composite list view in the page that you can use for ...
2012-05-10-CombineView-14.png

No comments:

Post a Comment