Question

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.

Was it helpful?

Solution

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;
                }
}
}
Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top