It is a reccurent subject : create a dropdowlist with checkboxes..
I followed this tutorial : https://www.c-sharpcorner.com/blogs/multiselect-dropdownlist-with-checkboxes-in-asp-net-with-c-sharp-and-vb-net-using-jquery-plugin
But Still I have the common error : "Uncaught TypeError: $(...).multiSelect is not a function"
Here is the render HTML :
<head>
<title>Listing</title>
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
<meta content="C#" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
<link href='/styles/stylesheet.css'
type="text/css" rel="stylesheet">
<script language="JavaScript" src='/scripts/utilities.js'
type="text/javascript"></script>
<script language="JavaScript" src='/scripts/sortList.js'
type="text/javascript"></script>
<script language="javascript" src='/scripts/listingConfirmation.js'
type="text/javascript"></script>
<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
});
$("#Button1").click(function () {
alert($(".multiselect-selected-text").html());
});
});
</script>
I tried with both "multiSelect" and "multiselect".
Here is the ListBox :
<td>
<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" runat="server" Text="Button" OnClick="Submit" />
</td>
The code behind is also done and works :
protected void Submit(object sender, EventArgs e)
{
string message = string.Empty;
foreach (ListItem item in lstFruits.Items)
{
if (item.Selected)
{
message += item.Text + " " + item.Value + "\\n";
}
}
ClientScript.RegisterClientScriptBlock(this.GetType(), "alert", "alert('" + message + "');", true);
}
The problem : My view still renders a ListBox and NOT a dropdownlist with Checkboxes, plus when I click on one Item it automatically refresh and shows the loading sign (minor problem)
What am I missing ? Why I can't see the dropdownlist as in the tutorial ?
Aucun commentaire:
Enregistrer un commentaire