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

Update in the SharePoint List using Client Object Model within a WebPart.

try
{
SPWeb currentWeb = SPContext.Current.Web;
ClientContext clientContext = new ClientContext(currentWeb.Url);
Web web = clientContext.Web;
List list = web.Lists.GetByTitle("Login");
CamlQuery query = new CamlQuery();
query.ViewXml = @"<Query><Where><Eq><FieldRef Name='ID' /><Value
Type='Counter'>" + ddlID.SelectedItem.Value + "</Value></Eq></Where></
Query>";
Microsoft.SharePoint.Client.ListItemCollection listItems =
list.GetItems(query);
clientContext.Load(listItems);
clientContext.ExecuteQuery();
foreach (Microsoft.SharePoint.Client.ListItem item in listItems)
{
if (ddlID.SelectedItem.Value == item["ID"].ToString())
{
item["Title"] = txtUserName.Text;
item["Password"] = txtPassWord.Text;
item.Update();
strError += "Updation Successful";
break;

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

No comments:

Post a Comment