How to get LookupField Information from a listItem

How to get LookupField Information from a listItem

If you want the ID or the value form a LookupField, you can get it easily with this code snippet:

SPListItem item = getitsomewhare...
SPFieldLookupValue lf =
    (SPFieldLookupValue)
     item.ParentList.Fields.GetField(_FieldName).GetFieldValue(
     item.GetFormattedValue(_FieldName));

if you got the field, fetch its properties via

if (lf == null)
{
    int itemID = lf.LookupId;
    string itemValue = lf.LookupValue;
}
Have fun 😉

Leave a Reply