I am currently in the process of developing a recipe website focused on meals. I have created an admin panel where I can manage the meals added to the site. One issue I am facing is with deleting a meal that was previously added. The menu displays the number of meals in each category, such as Pasta(4) for example. As an admin, I am able to successfully add a new meal to the website by selecting a category. However, when it comes to deleting a meal, there seems to be an issue. It always deletes the first value in the DropDownList, which is Meat Foods. Can anyone assist me in finding a solution to this problem?
Below is the code snippet:
if (Page.IsPostBack == false)
{
id = Request.QueryString["YemekId"];
islem = Request.QueryString["islem"];
SqlCommand komut2 = new SqlCommand("Select *from Kategoriler", baglan.baglanti());
SqlDataReader oku2 = komut2.ExecuteReader();
DropDownList1.DataTextField = "KategoriAd";
DropDownList1.DataValueField = "KategoriId";
DropDownList1.DataSource = oku2;
DropDownList1.DataBind();
SqlCommand komut = new SqlCommand("Select *from Yemek", baglan.baglanti());
SqlDataReader oku = komut.ExecuteReader();
DataList1.DataSource = oku;
DataList1.DataBind();
}
//deletion operation
if (islem == "sil")
{
SqlCommand komutsilme = new SqlCommand("Delete from Yemek where YemekId=@s1", baglan.baglanti());
komutsilme.Parameters.AddWithValue("@s1", id);
komutsilme.ExecuteNonQuery();
baglan.baglanti().Close();
SqlCommand kategorisil = new SqlCommand("Update Kategoriler set KategoriAdet=KategoriAdet-1 where KategoriId=@k1", baglan.baglanti());
kategorisil.Parameters.AddWithValue("@k1", DropDownList1.SelectedValue);
kategorisil.ExecuteNonQuery();
baglan.baglanti().Close();
Response.Write("<script> alert('Yemek başarıyla silindi!')</script>");
}