Prasad Bolla's SharePoint Blog

Click Here to go through the Interesting posts within my Blog.

Click Here to go through the new posts in my blog.

Thursday, December 01, 2011

Search Record from SharePoint List using Client Object Model in a WebPart

try
{
SPWeb currentWeb = SPContext.Current.Web;
Microsoft.SharePoint.Client.ClientContext ctx = new
Microsoft.SharePoint.Client.ClientContext(currentWeb.Url);
Microsoft.SharePoint.Client.List lstLogin =
ctx.Web.Lists.GetByTitle("Login");
Microsoft.SharePoint.Client.CamlQuery sQuery =
Microsoft.SharePoint.Client.CamlQuery.CreateAllItemsQuery();
sQuery.ViewXml = @"<View><FieldRef Name='Title' /><FieldRef
Name='Password' /><Query><Where><Eq><FieldRef Name='ID' /><Value
Type='Counter'>" + ddlID.SelectedItem.Value + "</Value></Eq></Where></
Query></View>";
Microsoft.SharePoint.Client.ListItemCollection myColl =
lstLogin.GetItems(sQuery);
ctx.Load(myColl);
ctx.ExecuteQuery();
if (myColl.Count > 0)
{
foreach (Microsoft.SharePoint.Client.ListItem item in myColl)
{
txtUserName.Text = item["Title"].ToString();
txtPassWord.Text = item["Password"].ToString();
ctx.Load(lstLogin.GetItems(sQuery));

}
}
}
catch (Exception ex)
{
strError += ex.ToString();
}

No comments:

Post a Comment