A lookup field takes its value from a field in another list. The list that provides data for the lookup field is called the lookup list. To get a reference to the lookup list, access the SPFieldLookup object's LookupList property. To determine which field in the lookup list is providing information, access the LookupField property.
Although the SPFieldLookup class does have a constructor, it is often more convenient to call the AddLookup method of the SPFieldCollection class. The AddLookup method has an overload that you can use to create a lookup to a list in a different Web site from the one where you are creating the SPFieldLookup object.
Microsoft SharePoint Foundation supports multiple-column lookups. In this case, a primary column establishes the relationship with the lookup list by pointing to a field in the target list, and one or more secondary columns point to other fields in the target list. You can create the lookup field for a secondary column by calling the AddDependentLookup method of the SPFieldCollection class. For a secondary column, the IsDependentLookup property returns true. For a primary column, IsDependentLookup returns false and the IsRelationship property returns true.
SharePoint Foundation supports referential integrity for list items by making it possible for lookup fields to set deletion constraints on the lookup list. You do this through the RelationshipDeleteBehavior property, which takes one of the following SPRelationshipDeleteBehavior enumeration values:
Cascade . Deleting an item from the lookup list causes all related items to be deleted from the list that contains the lookup field.
Restrict . Prevents an item on the lookup list from being deleted if related items exist on the list that contains the lookup field.
None . No constraint (the default).
In order to specify either Cascade or Restrict, the user must have SPBasePermissions.ManageLists permission on the lookup list. In addition, both Cascade and Restrict require that the lookup field be indexed. Before setting the RelationshipDeleteBehavior property to either of these values, first set the Indexed property to true.
Microsoft SharePoint Foundation supports multiple-column lookups. In this case, a primary column establishes the relationship with the lookup list by pointing to a field in the target list, and one or more secondary columns point to other fields in the target list. You can create the lookup field for a secondary column by calling the AddDependentLookup method of the SPFieldCollection class. For a secondary column, the IsDependentLookup property returns true. For a primary column, IsDependentLookup returns false and the IsRelationship property returns true.
SharePoint Foundation supports referential integrity for list items by making it possible for lookup fields to set deletion constraints on the lookup list. You do this through the RelationshipDeleteBehavior property, which takes one of the following SPRelationshipDeleteBehavior enumeration values:
Cascade . Deleting an item from the lookup list causes all related items to be deleted from the list that contains the lookup field.
Restrict . Prevents an item on the lookup list from being deleted if related items exist on the list that contains the lookup field.
None . No constraint (the default).
In order to specify either Cascade or Restrict, the user must have SPBasePermissions.ManageLists permission on the lookup list. In addition, both Cascade and Restrict require that the lookup field be indexed. Before setting the RelationshipDeleteBehavior property to either of these values, first set the Indexed property to true.
using System;