A simple way to create a look field relation with the SharePoint List. In this blog I will create a one site column of type lookup, and add to the newly created content type. Helpful links for lookup fields in SharePoint 2010 are Provisioning Lookup Fields, lookup fields by msdn .I have document here in my blog so that I will have clear picture of lookup fields. In this blog I am going to add a look up field to a list trough visual studio 2010, simple step by step with the simple project.
First We Create a List Instance in the Visual Studio2010.
We will Add our Created Lookup Field to this List .
As Lookup Fields obtain their values from an existing list. Each Lookup Field is being linked to its list using the list’s ID. As the ID’s are being generated after creating the instances there is no way to provision a Lookup Field linked to a newly created list during Solution deployment.
(1) Create Empty SharePoint Project
(2) Deployed it as Sandbox Solution
(3) Adding List Instance to the Project. This List column will be use as a lookup column in the main list.
List Name is GenreLooupField.
(4) Adding Default Rows to the List
(5) We will add a Site column definition by adding a new empty element in the project.
(6) Add the definition for the site column.
Type of this column is LookUp
At this stage site column with the list definition has created. Next is to create the content type in which above site column will be mentioned. Last step will add this content type to our movie list.
(7)Add new item (Content type) in the project
Choose the Announcement to this content type inherit form, then open the element.xml below the content type and add the the reference of the site column through ID.
Deploy the Project.
Go to the List Setting then Advance Setting ,Allow management of content types. Add the content type which we created above. then click below on list setting-> Add from existing site content types
Make added content type as default content type of list (movie).
Look up field added to the list.