Shahid Alam

Shahid Alam

  • 1.5k
  • 133
  • 921

Unable to delete ItemList

Apr 20 2022 12:15 AM
protected void Button_Click3(object sender, EventArgs e) 
{

    //Get the SP site  
    using (SPSite oSite = new SPSite(SPContext.Current.Web.Url))
    {
        //Get the Web site  
        using (SPWeb Web = oSite.OpenWeb())
        {
            // If List not exist it will throw an error  
            SPList myList = Web.Lists["Employee"];

            SPListItem itemToworkWith = myList.GetItemById(9);
            SPFieldUserValueCollection city = (SPFieldUserValueCollection)itemToworkWith["city"];

            foreach (SPFieldUserValue citys in city)
            {
                itemToworkWith["Title"] = TextBox1.Text;
                itemToworkWith.Delete();
            }
        }
    }
} 

I was using the above command to delete an Item with an ID 9 but the list Item was not getting deleted

Kindly help


Answers (3)