带复选框ASP的DropDownlist

时间:2018-10-11 08:56:28

标签: c# asp.net checkbox listbox dropdown

这是一个经常发生的主题:创建带有复选框的下拉列表。

我遵循了本教程: https://www.c-sharpcorner.com/blogs/multiselect-dropdownlist-with-checkboxes-in-asp-net-with-c-sharp-and-vb-net-using-jquery-plugin

但是我仍然有一个常见错误: “未捕获的TypeError:$(...)。multiSelect不是函数”

以下是渲染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>

我尝试同时使用“ multiSelect”和“ multiselect”。

这是列表框:

<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>

后面的代码也已经完成并且可以工作:

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);
}

问题:我的视图仍然呈现一个列表框,而不是带有复选框的下拉列表,另外,当我单击一个项目时,它会自动刷新并显示加载符号(次要问题)

我想念什么?为什么我看不到教程中的下拉列表?

0 个答案:

没有答案