我正在嘗試使用帶有 Bootstrap Multiselect 樣式的 ListBox 控制元件在 ASP.NET 中創建一個多選 ListBox。
至于外觀,它運作良好。我可以將其切換為下拉,我可以選擇和取消選擇選項并關閉它。
<asp:ListBox ID="NameListBox" runat="server" CssClass="multiselect" SelectionMode="Multiple" OnSelectedIndexChanged="NameListBox_SelectedIndexChanged">
<asp:ListItem Text="Name 1" />
<asp:ListItem Text="Name 2" />
<asp:ListItem Text="Name 3" />
<asp:ListItem Text="Name 4" />
<asp:ListItem Text="Name 5" />
<asp:ListItem Text="Name 6" />
</asp:ListBox>
我遇到的問題是進行回發并處理新選擇的專案。我有一個 OnSelectedIndexChanged 寫在我回圈選擇的專案并將它們插入到資料庫中,但我不知道何時以及如何運行它。我知道我可以有一個單獨的按鈕來引起回發并保存所選專案,但我想在關閉 ListBox 時引起自動回發。
問題是,如果我使用 AutoPostBack="true",那么每次更改選項時都會發生回發,因此用戶除了一次保存之外無法選擇更多選項。我只想在下拉串列實際關閉時引起回發。
經過多次嘗試,我得到了這個:
$('.multiselect').multiselect({
nonSelectedText: '',
nSelectedText: 'selected',
allSelectedText: 'Everyone',
numberDisplayed: 2,
buttonTextAlignment: 'left',
buttonWidth: 240,
onDropdownHidden: function (event) {
__doPostBack($(event.target).parent().children('.multiselect').attr('id'), '');
}
});
這會在關閉串列框的下拉串列后導致回發,這很好。但遺憾的是,NameListBox_SelectedIndexChanged 事件處理程式在回發期間沒有被觸發,因此什么也沒有發生。
有小費嗎?
uj5u.com熱心網友回復:
希望可以幫到你~
<asp:ListBox ID="DropDownList_ExportCountry" runat="server" SelectionMode="Multiple" OnSelectedIndexChanged="DropDownList_ExportCountry_SelectedIndexChanged"></asp:ListBox>
在 html <form 我把這個
<script type="text/javascript">
$('[id*=DropDownList_ExportCountry]').multiselect({
onDropdownHide: function (event) {
__doPostBack();//__doPostBack($(event.target).parent().children('#DropDownList_ExportCountry').attr('id'), '')
}
});
并記住在 <head 中包含這樣的 js 和 Css
<link href="http://cdn.rawgit.com/davidstutz/bootstrap-multiselect/master/dist/css/bootstrap-multiselect.css" rel="stylesheet" type="text/css" />
<script src="http://cdn.rawgit.com/davidstutz/bootstrap-multiselect/master/dist/js/bootstrap-multiselect.js" type="text/javascript"></script>
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/390773.html
標籤:C# 网站 推特引导 bootstrap-4 引导多选
