Wednesday, 17 February 2010

Reading Multiple Values of SPFieldLookup Column Programmatically ...

//
// Returns the value of a Lookup-Field with multiple values.
//


public static IEnumerable GetFieldValueLookupCollection(this SPListItem item, string fieldName)
{
List result = new List();
if (item != null)
{
SPFieldLookupValueCollection values = item[fieldName] as SPFieldLookupValueCollection;

foreach (SPFieldLookupValue value in values)
{
result.Add(value.LookupValue);
}
}
return result;
}


Example:
// Read lookup values of a SPFieldLookup field with multiple values allowed

IEnumerable values = item.GetFieldValueLookupCollection("MultiLookupFieldName");

No comments:

Post a Comment