i am not able to getitembyId for select , and also not able to update and delete
while updating it is showing that the item from the list is deleted but the item is present in list
protected void Upd_btn_Click(object sender, EventArgs e)
{
SPSite mySite = new SPSite("http://ow-------hidden--------/");
SPWeb myWeb = mySite.OpenWeb();
SPList myList = myWeb.Lists["Datalist"];
SPListItem item = myList.GetItemById(Convert.ToInt32(TextBox1.Text));
// Populate textboxes with item data
TextBox1.Text = item["Id"].ToString();
TextBox2.Text = item["Designation"].ToString();
TextBox3.Text = item["Name"].ToString();
TextBox4.Text = item["City"].ToString();
TextBox5.Text = item["State"].ToString();
Label1.Text = "Item found";
SPListItem itemToUpdate = myList.GetItemById(Convert.ToInt32(TextBox1.Text));
if (itemToUpdate != null)
{
itemToUpdate["Title"] = TextBox2.Text;
itemToUpdate["Name"] = TextBox3.Text;
itemToUpdate["City"] = TextBox4.Text;
itemToUpdate["State"] = TextBox5.Text;
itemToUpdate.Update();
Label1.Text = "Item Updated Successfully";
}
else
{
Label1.Text = "Item not found";
}
}
New contributor
Shaikh Mohd saif is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.