1

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;

    }

2 Answers 2

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.)

-1

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);
1
  • 1
    That all are not client object model approaches. Please, read the question intently before you answer. Sep 15, 2011 at 8:02

Your Answer

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

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