Wednesday 17 February 2010

Setting Single Value of SPFieldLookup Column Programmatically ...

///
/// 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");

No comments:

Post a Comment