Tech Space

The Technical Solution Space for SharePoint 2010, MOSS 2007, and .Net (C#, VB.Net)

///


/// Sets the value of a Lookup-Field.
///


public static void SetFieldValueLookup(this SPListItem item, string fieldName, string lookupValue)
{
if (item != null)
{
SPFieldLookup field = item.Fields.GetField(fieldName) as SPFieldLookup;
item[fieldName] = GetLookupValue(item.Web, field, lookupValue);
}
else
{
item[fieldName] = null;
}
}


Example:

// Set the value of a SPFieldLookup field

item.SetFieldValueLookup("LookupFieldName", "LookupValue");

0 comments:

Post a Comment