0
當我改變DropDownList的ddlCO的價值,我不能清潔值的DropDownListddlCountry。我使用DataSet。清除的DropDownList值C#
上的值DropDownListddlCountry合併。
如何解決這個問題?
我的代碼如下,預先感謝您的任何幫助,真的很感激。
protected void ddlCO_SelectedIndexChanged(object sender, EventArgs e)
{
sql = @String.Format(" SELECT * FROM ");
sql += String.Format(" `tbl_1` WHERE Country IN (?); ");
using (OdbcConnection cn =
new OdbcConnection(ConfigurationManager.ConnectionStrings["ConnMySQL"].ConnectionString))
{
using (OdbcCommand cmd =
new OdbcCommand(sql, cn))
{
cmd.Parameters.AddWithValue("param1", ddlCO.SelectedItem.Value);
cmd.CommandType = CommandType.Text;
cmd.Connection.Open();
using (OdbcDataAdapter sda =
new OdbcDataAdapter(cmd))
{
ddlCountry.AppendDataBoundItems = true;
ddlCountry.ClearSelection();
ddlCountry.Enabled = true;
DataSet ds = new DataSet();
sda.Fill(ds);
ddlCountry.DataSource = ds.Tables[0];
ddlCountry.DataTextField = "CountryText";
ddlCountry.DataValueField = "CountryValue";
ddlCountry.DataBind();
}
}
}
}
嘗試以清除它'.DataSource = null' – EpicKip
@EpicKip謝謝你的幫助,但* DropDownList的* ** ** ddlCountry不空。 –
該列表是否仍然填滿或僅包含上次選擇的項目的文本?因爲如果我將數據源設置爲空,我的組合框立即清除 – EpicKip