在“ Page_Load”上,我用数据源填充一个DropDownList:
lstBoxGrupAcessID.DataTextField = "Description";
lstBoxGrupAcessID.DataValueField = "ID";
lstBoxGrupAcessID.DataSource = new BLLCompany().SelectLstGroupBox(objCompany.CompanyID);
lstBoxGrupAcessID.DataBind();
此后,我需要为lstBoxGrupAcess设置一些预先选择的itens(针对每个公司)(仅作为示例,我将在lstBoxGrupAcessID上选择所有itens)
foreach (ListItem itm in lstBoxGrupAcessID.Items)
itm.Selected = true;
执行页面时,出现此错误:
Cannot have multiple items selected in a DropDownList.
我的代码中SumoSelect的初始化为:
<script>
$(document).ready(function () {
var list = $('#<%=lstBoxGrupAcessID.CompanyID%>');
list.SumoSelect({
selectAll: false
});
});
Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);
function EndRequestHandler(sender, args) {
var list = $('#<%=lstBoxGrupAcessID.CompanyID%>');
list.SumoSelect({
selectAll: false
});
}
</script>
我的DropDownList的声明是:
<asp:DropDownList ID="lstBoxGrupAcessID" runat="server" multiple="multiple" CssClass="form-control"></asp:DropDownList>
答案 0 :(得分:0)
您必须使用asp:ListBox来选择多个项目,而不是下拉菜单