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

Delete ListItem in the SharePoint List using Server Side Code

if (txtUserName.Text != "")
{
       SPWeb currentWeb = SPContext.Current.Web;
       SPList lstLogin = currentWeb.Lists["Login"];
       SPListItemCollection myColl = lstLogin.Items;
       foreach (SPListItem item in myColl)
       {
              if (item["UserName"].ToString() == txtUserName.Text)
              {
                     item["PassWord"] = txtPassWord.Text;
                     item.Delete();
                     lblMessage.Text = "Deletion Successful";
                     Clear();
                     break;
              }
       }
}
Note:-
Here The above are having clear function here i am keeping the Clear function
public void Clear()
{
       txtUserName.Text = "";
       txtPassWord.Text = "";
       txtUserName.Focus();
}

No comments:

Post a Comment