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.

Friday, December 02, 2011

Search ListItem in the SharePoint List using Server Side Code


Note:- Here Title is the Primary Key.
if (txtUserName.Text != "")
{
       SPWeb currentWeb = SPContext.Current.Web;
       SPList lstLogin = currentWeb.Lists["Login"];
       SPQuery sQuery = new SPQuery();
       sQuery.Query = "<Where><Eq><FieldRef Name='UserName' /><Value
       Type='Text'>" + txtUserName.Text.ToString().ToLower() + "</Value></Eq></Where>";
       SPListItemCollection myColl = lstLogin.GetItems(sQuery);
       if (myColl.Count > 0)
       {
              SPListItem item = myColl[0];
              txtPassWord.Text = item["PassWord"].ToString();
       lblMessage.Text = "Record Found " + txtUserName.Text;
       }
}

No comments:

Post a Comment