Share via


AddLookup Method

The AddLookup method of the SPFieldCollection class creates a lookup field in the collection of fields for a list. A lookup field refers to values from a field in another list.

Parameters

strDisplayName   A string that specifies the display name of the field.

lookupListId   A GUID that specifies the target list for the lookup field.

bRequired  true to require that the field contain values; otherwise, false.

Return Value

A string that contains the internal name used for the field.

Example

The following code example adds a required lookup field with the specified display name and lookup ID to a list.

This example requires using directives (Imports in Visual Basic) for both the Microsoft.SharePoint and Microsoft.SharePoint.WebControls namespaces.

Requirements

Platforms: Microsoft Windows Server 2003

Security: Code Access Security