不能在DropDownList 中选择多个项
Posted Sam Lin
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了不能在DropDownList 中选择多个项相关的知识,希望对你有一定的参考价值。
在绑定DropDownList时如果出现多次绑定,会出错以下错误:
“不能在DropDownList 中选择多个项”
经了解,只需要在选中值是清空选择即可:xxDropDownList.ClearSelection() ;
/// <summary>
/// 设定选中项
/// </summary>
/// <param name="list"></param>
public static void SetListControl(ListControl list, string selectedValues)
{
if (string.IsNullOrEmpty(selectedValues))
return;
list.ClearSelection();
foreach (string var in selectedValues.Split(‘,‘))
{
string value = var.Trim();
if (value.Length > 0)
{
foreach (ListItem item in list.Items)
{
if (item.Value == value)
{
item.Selected = true;
break;
}
}
}
}
}
以上是关于不能在DropDownList 中选择多个项的主要内容,如果未能解决你的问题,请参考以下文章
如何实现DropDownList控件的某一项只能被选择一次?
gridview中用dropdownlist更改值来筛选,更改dropdownlist之后无法进行checkbox选择