'Multiselect dropdownlist with Checkbox in asp.net
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:
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.
Solution 1:[1]
Please remove first 2 <script>
and 2 <link>
tags and don't remove last <script>
and <link>
tag. Your problem will be solved.
Solution 2:[2]
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
For more details you can refer below link http://www.codewithasp.net/2015/04/jquery-multiselect-dropdown-in-aspnet.html
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Opal |
Solution 2 |