[英]How to get all the values selected in a RadComboBox(multi-select drop-down) with check boxes on the server-side, asp.net?
[英]Using Drop-down with Check-boxes in Asp.net
我有2個下拉框,我希望第一個下拉框像級聯一樣過濾第2個,因此第一個下拉框具有復選框,我希望將所選項目從第一個傳遞到第二個,但是要獲得“語法”錯誤”。 我將其運行到調試模式,輸出結果如下所示
CommandText "select id, name FROM myTable where id in (''CKU019','CW5036'') "
並且CKU019附近似乎有多余的撇號。 這是我的代碼
protected void bindDDL()
{
string selectedValues = string.Empty;
foreach (ListItem item in ddchkCountry.Items)
{
if (item.Selected)
selectedValues += "'" + item.Value + "',";
}
if (selectedValues != string.Empty)
selectedValues = selectedValues.Remove(selectedValues.Length - 1);
SqlConnection con = new SqlConnection(strConnString);
con.Open();
SqlCommand cmd = new SqlCommand("select id, name FROM myTable where id in ('" + selectedValues + "')", con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
con.Close();
facDDL.DataSource = ds;
facDDL.DataTextField = "name";
facDDL.DataValueField = "id";
facDDL.DataBind();
}
刪除多余的'包裝您選擇的值...
SqlCommand cmd = new SqlCommand(“選擇ID,名稱為myTable,其中ID在(” + selectedValues +“)”,con)中;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.