0

I have an SPListItem from a SPList That contains a Lookup Field. How do I do to get the SPFieldLookup object from this item? I need to get the other fields from this object an not only the title.

1 Answer 1

0

On basis of your question, i understand you want to get value of SPFieldLookup Column programmatically. Correct me if i am wrong.

Assuming My Skill is the list that contains Skill field which is lookup, following code will fetch the value of Skill field

using (SPSite site = new SPSite("http://URL"))
        {
            using (SPWeb web = site.OpenWeb())
            {
                SPList list = web.Lists["My Skill"]; //My Skill is the list contains Skill as a lookup field
                SPListItemCollection itemCollection= list.Items;

                //Retrieve lookup fields
                foreach (SPListItem item in itemCollection)
                {
                    SPFieldLookupValue lookupField = new SPFieldLookupValue(item["Skill"].ToString());
                    string lookUpValue = lookupField.LookupValue;
                }
}
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.