BootstrapmultiSelect在页面POSTBack后不显示。
使用Bootstrap multip select
1.必须引用一个CSS文件,JQuery JS和两个bootstrap JS文件
2.当一个DropDownListChanged Index并且PagePostBack,pHideChoice显示(但是multiSelect不显示)
3.解决办法,把DropDownList的ChangeEvent注册到pageLoad事件中而非document.ready事件中
function initMultiSelect() {
var hideChoices = $("#<%=hfHideChoices.ClientID %>").val();
var listChoices = [];
if (hideChoices != null && hideChoices != "") {
listChoices = hideChoices.split(",");
}
$("#<%=ddlHideChoices.ClientID %>").val(listChoices);
}
function pageLoad() {
initMultiSelect();
$("#<%=ddlHideChoices.ClientID %>").change(function () {
var choices = $(this).val();
var hideChoices = $("#<%=hfHideChoices.ClientID %>").val();
if (hideChoices != null && hideChoices != "") {
var selectedCount = hideChoices.split(",").length;
var totalCount = $(this).children('option').length;
if (selectedCount + 1 == totalCount) {
alert("Notes: You cann't select all items.");
}
}
if (choices == null) {
$("#<%=hfHideChoices.ClientID %>").val("");
} else {
$("#<%=hfHideChoices.ClientID %>").val(choices.join());
}
});
$("#<%=ddl_Type.ClientID%>").change(function () {
$("#pHideChoice").hide();
if ($(this).val() == "7") {
$('.selectpicker').selectpicker('show');
$("#pHideChoice").show();
} else {
$('.selectpicker').selectpicker('hide');
}
});
if ($("#<%=ddl_Type.ClientID%>").val()=="7")
{
$('.selectpicker').selectpicker('show');
$("#pHideChoice").show();
}
}