Archive | August 2012

Autocomplete suggestion in sharepoint using silverlight client object model

In this article i would like to share with you the implementation of auto-complete suggestion in sharepoint using silverlight control.I have considered  ‘AutoCompleteBox’ control in silverlight and have bounded the ‘Title’ of a sharepoint list.

Here goes the code :

MainPage.xaml

<sdk:AutoCompleteBox Height=”28″ HorizontalAlignment=”Left” Name=”autoCompleteBox1″ VerticalAlignment=”Top” Width=”195″  FilterMode=”Contains”  Grid.Column=”2″  />

MainPage.xaml.cs

ClientContext clientContext = new ClientContext(ApplicationContext.Current.Url);
clientContext.Load(clientContext.Web);
list = clientContext.Web.Lists.GetByTitle(“Sample”);
clientContext.Load(list);
ListItemCollection itemColl = list.GetItems(CamlQuery.CreateAllItemsQuery());
clientContext.Load(itemColl);
clientContext.ExecuteQueryAsync(new ClientRequestSucceededEventHandler(OnSucceed), null);

private void OnSucceed(object sender, ClientRequestSucceededEventArgs args)
{
Dispatcher.BeginInvoke(BindData);
}

private void BindData()
{
List<string>searchItems = new List<string>();

if (itemColl.Count > 0)
{

foreach (ListItem item in itemColl)
{
searchItems.Add(item[Constants.title].ToString());
}
}
autoCompleteBox1.ItemsSource = searchItems;
autoCompleteBox1.Focus()
}

The below screenshot shows the ‘Title’ of the sharepoint list being populated :