首页 > 其他 > 详细

不能在DropDownList 中选择多个项

时间:2016-09-20 18:09:07      阅读:286      评论:0      收藏:0      [点我收藏+]

在绑定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 中选择多个项

原文:http://www.cnblogs.com/samlin/p/5889636.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!