Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

new to the development world, not to sharepoint.

I'm ultimately trying to populate a listbox with items from a multivalue lookup field. If it's a single lookup, no problem. When I make it a multi it's blank. Hopefully the below is enough to make sense of what the heck I'm doing. An example of what my code should look like would help this novice out tremendously.

public class NLPLibraryColumns
{
    public string Title { get; set; }
    public string Body { get; set; }
    public string DocumentsLink { get; set; }
}
private static ClientContext context = null;
public static ListItemCollection libListItems { get; set; }
ObservableCollection<NLPLibraryColumns> gLibCol = new ObservableCollection<NLPLibraryColumns>();

private void BindData()
    {
        var list = new List<NLPLibraryColumns>();

        foreach (var itm in Global.libListItems)
        {
            list.Add(new NLPLibraryColumns
            {
                DocumentsLink = ((FieldLookupValue)itm["DocumentsLink"]).LookupValue,
                Body = itm["Body"].ToString(),
                Title = itm["Title"].ToString(),
            });
        }
        rGrid1.ItemsSource = list;

    }
share|improve this question

2 Answers 2

The lookup field returns a value of type FieldLookupValue with two properties for retrieving the LookupID and LookupValue, but the multi-lookup field returns FieldLookupValue[] -- and array of FieldLookupValues.

To do what your wanting, just iterate thru the array before binding the values.

I posted a code example of getting at the values of a multi-lookup field in this question: How to retrieve lookup values using ClientContext?. (The example is not specifically for the SilverLight client object model, but should get you moving in the right direction.)

share|improve this answer

Take a look at this link...

http://mossipqueen.wordpress.com/2010/01/12/getting-splistitems-from-a-multi-value-lookup-column/

or try this

In your query be sure to set LookupId to TRUE:

SPList productsList = SPContext.Current.Web.Lists["Products"];

SPQuery query = new SPQuery();
query.Query = "<Where><Eq>" +
    "<FieldRef Name='AvailableColors' LookupId='TRUE' />" +
    "<Value Type='Lookup'>1</Value>" +
    "</Eq></Where>";

SPListItemCollection results = productsList.GetItems(query);
share|improve this answer
1  
That all are not client object model approaches. Please, read the question intently before you answer. –  Andrey Markeev Sep 15 '11 at 8:02

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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