How to retrieve multiple lookup values from sharepoint using silverlight

How to retrieve multiple lookup values from sharepoint using silverlight:


In the below example  i  have  get values from a multi values Look Up Field  and  populated a  treeview.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace multilookupvalue
{
public partial class MainPage : UserControl
{
ClientContext cc;
string name;
int recordno;
public MainPage()
{

InitializeComponent();
cc = new ClientContext(ApplicationContext.Current.Url);
cc.Load(cc.Web);
listobj = cc.Web.Lists.GetByTitle("your list name");
List s = cc.Web.SiteUserInfoList;
cc.Load(listobj);
CamlQuery qry= new CamlQuery();
qry.ViewXml = "<view/>";
_lsititemcoll = listobj.GetItems(qry);
cc.Load(_listitemcoll);
cc.ExecuteQueryAsync(new ClientRequestSucceededEventHandler(OnRequestSucceeded), null);

}
private void OnRequestSucceeded(Object sender, ClientRequestSucceededEventArgs args)
{

// This is not called on the UI thread.
Dispatcher.BeginInvoke(datacon);

}
private void datacon()
{
recordno = 1;
treeview tv1 = new treview();
foreach(ListItem li in _listitemcoll)
{

FieldLookupValue[]  fvalue  =   li["lookup column  name"]  as FieldLookupValue[];
TreeViewItem item = new TreeViewItem();
item.Header = "Record" + recordno;
for(int i=0;i<fvalue.Count();i++)
{

TreeViewItem subitem = new TreeViewItem();
subitem.Header =fvalue[i].LookUpValue;
item.Items.Add(subitem);

}
tv1.Children.Add(item);
LayoutRoot.Children.Add(tv1); 
}

}
}

Comments

Popular posts from this blog

Upload Single/Multiple file by using the REST API and jQuery SharePoint 2013

Add content type to SharePoint List/Library using REST API

A type named 'SP.Data. could not be resolved by the model error