我有一个奇怪的问题。我用这段代码填充下拉列表
MySqlCommand cmdAreaPassive = new MySqlCommand();
cmdAreaPassive.CommandText = "Select BolgeID, BolgeAdi, AktiPasif ";
cmdAreaPassive.CommandText += "From tbl_bolgeler ";
cmdAreaPassive.CommandText += "Where AktiPasif = 1 ";
cmdAreaPassive.CommandText += "Order By BolgeAdi ASC ";
cmdAreaPassive.Connection = con;
MySqlDataAdapter drAreaPassive = new MySqlDataAdapter(cmdAreaPassive);
DataSet dsAreaPassive = new DataSet();
drAreaPassive.Fill(dsAreaPassive);
ddlAreaDelete.DataSource = dsAreaPassive;
ddlAreaDelete.DataTextField = "BolgeAdi";
ddlAreaDelete.DataValueField = "BolgeID";
ddlAreaDelete.DataBind();
Response.Redirect(Request.RawUrl);
我尝试使用此代码删除项目
MySqlCommand cmdDelete = new MySqlCommand();
cmdDelete.CommandText = "Update tbl_bolgeler ";
cmdDelete.CommandText += "Set AktiPasif = @AktiPasif ";
cmdDelete.CommandText += "Where BolgeID = @BolgeID ";
cmdDelete.Connection = con;
cmdDelete.Parameters.AddWithValue("@BolgeID", ddlAreaDelete.SelectedItem.Value);
cmdDelete.Parameters.AddWithValue("@AktiPasif", "0");
cmdDelete.ExecuteNonQuery();
一切正常,直到选择对象。它必须采用选定的值,但它需要选定的索引。我尝试 SelectedItem.Value 和 SelectedValue 但它们都不起作用。对不起我的英语不好,谢谢。