twitter-bootstrap asp.net 中带有复选框的多选下拉列表
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28103590/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Multiselect dropdownlist with Checkbox in asp.net
提问by King_Fisher
I'm using bootstrap multiselect dropdown list with checkbox.its working well without master form.but its not working with master forms:
我正在使用带有复选框的引导多选下拉列表。它在没有主表单的情况下运行良好。但它不适用于主表单:
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<link href="http://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.0.3/css/bootstrap.min.css"
rel="stylesheet" type="text/css" />
<script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.0.3/js/bootstrap.min.js"></script>
<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>
<script type="text/javascript">
$(function() {
$('[id*=lstFruits]').multiselect({
includeSelectAllOption: true
});
});
</script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<asp:ListBox ID="lstFruits" runat="server" SelectionMode="Multiple">
<asp:ListItem Text="Mango" Value="1" />
<asp:ListItem Text="Apple" Value="2" />
<asp:ListItem Text="Banana" Value="3" />
<asp:ListItem Text="Guava" Value="4" />
<asp:ListItem Text="Orange" Value="5" />
</asp:ListBox>
<asp:Button ID="Button1" Text="Submit" runat="server" OnClick="Submit" />
</asp:Content>
C# Code:
C# 代码:
protected void Submit(object sender, EventArgs e)
{
string message = "";
foreach (ListItem item in lstFruits.Items)
{
if (item.Selected)
{
message += item.Text + " " + item.Value + "\n";
}
}
ClientScript.RegisterClientScriptBlock(this.GetType(), "alert", "alert('" + message + "');", true);
}
I have referred
我已经提到
by using this code i have a drop down list on the Page but the drop down click event it not firing i couldn't see any list. kindly assist me to solve this.
通过使用此代码,我在页面上有一个下拉列表,但下拉单击事件未触发,我看不到任何列表。请帮助我解决这个问题。
回答by Ahsan
Please remove first 2 <script>and 2 <link>tags and don't remove last <script>and <link>tag. Your problem will be solved.
请删除前 2 个<script>和 2 个<link>标签,不要删除最后一个<script>和<link>标签。你的问题将得到解决。
回答by Nikhil Gaur
I know this post seems to be few month old now but for other users here is the solution.
我知道这篇文章现在似乎已经有几个月的历史了,但对于其他用户来说,这里是解决方案。
First thing is, use best practise of defining id directly like below. (you may need to set ClientID mode as static)
$('#lstFruits').multiselect({ includeSelectAllOption: true });
To fire ListBox selected index change (I am assuming by drop down click event you mean selected index change) set listbox's autopostback property to true
首先,使用直接定义 id 的最佳实践,如下所示。(您可能需要将 ClientID 模式设置为静态)
$('#lstFruits').multiselect({ includeSelectAllOption: true });
要触发 ListBox 选定的索引更改(我假设下拉单击事件是指选定的索引更改)将列表框的 autopostback 属性设置为 true
For more details you can refer below link http://www.codewithasp.net/2015/04/jquery-multiselect-dropdown-in-aspnet.html
有关更多详细信息,您可以参考以下链接 http://www.codewithasp.net/2015/04/jquery-multiselect-dropdown-in-aspnet.html

