嗨即時通訊使用下拉列表從表中獲取id,然後刪除行刪除buton當我運行頁面時dropdownlist獲取表中所有的id都好,但當我刪除它始終刪除最後一個ID,即使我選擇另一使用下拉列表從數據庫中刪除
List<classe_cv_langues> li6 = new List<classe_cv_langues>();
SqlConnection con4 = new SqlConnection(@"Data Source=p5-pc\sqlexpress;Initial Catalog=recrutement_online_3;Integrated Security=True");
SqlCommand cmd4 = new SqlCommand();
cmd4.Connection = con4;
con4.Open();
cmd4.CommandText = "select id from cv_langues as cl inner join cv as c on cl.id_cv = c.id_cv where id_candidat= " + Session["Id_candidat"];
SqlDataReader dr4 = cmd4.ExecuteReader();
while (dr4.Read())
{
classe_cv_langues p6 = new classe_cv_langues();
p6.Id = int.Parse(dr4[0].ToString());
li6.Add(p6);
}
dr4.Close();
con4.Close();
DropDownList7.DataSource = li6;
DropDownList7.DataTextField = "id";
DropDownList7.DataValueField ="id";
DropDownList7.DataBind()
刪除布敦:
SqlConnection con = new SqlConnection(@"Data Source=p5-pc\sqlexpress;Initial Catalog=recrutement_online_3;Integrated Security=True");
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
con.Open();
cmd.CommandText = "delete from cv_langues where id='"+DropDownList7.SelectedValue+"'";
cmd.ExecuteNonQuery();
con.Close();
Server.Transfer("gestion_cv.aspx");
是您的數據綁定的邏輯指令只使用Page.IsPostback =假? –
對不起,我是一個新的程序員,我怎麼看到這個? –
如果您正在填充Page_Load方法的組合,請確保僅在Page.IsPostback = false時才執行此邏輯。添加這個作爲答案,以幫助解決問題 –