【问题标题】:How to access multiselect dropdownlist using asp.net c#如何使用asp.net c#访问多选下拉列表
【发布时间】:2016-11-28 15:58:45
【问题描述】:

我有一个这样的多选下拉列表:

<select id="ddMonths" multiple="multiple">
    <option value="oneM" selected="selected"> OneMonth</option>   
    <option value="twoM" selected="selected">TwoMonths</option>
    <option value="threM" selected="selected">ThreMonths</option>
    <option value="fourM" selected="selected">FourMonths</option>
    <option value="fiveM" selected="selected">FiveMonths</option>     
    <option value="SixM" selected="selected">SixMonths</option>

</select>

和javascript:

  $(document).ready(function () {
        $('#ddMonths').multiselect();
    });

我有一个这样的 html 表:

<table>
    <thead>
        <tr>
            <th >Something</th>
            <th>Something1</th>
            <th>Something2 </th>
            <th >Something3 </th>
            <th>Something4 </th>
        </tr>

    </thead>
    <tbody id="trBoth">
        <asp:Literal ID="allSomething" runat="server"></asp:Literal>
    </tbody> 
</table>

我使用后面代码中的文字填充表格。 我想使用多选下拉列表中的选定项目来控制表的值是否可能???如何从后面的代码中访问选定的项目?我正在使用 asp.net C#。我需要你的帮助。

【问题讨论】:

    标签: javascript c# asp.net


    【解决方案1】:

    我希望在这种情况下避免使用DropDownList 并使用ListBox

    查看ListBox 控件以允许多选。

    <asp:ListBox runat="server" ID="lblMultiSelect" SelectionMode="multiple">
        <asp:ListItem Text="One" Value="OneM" />
        <asp:ListItem Text="Two" Value="TwoM" />
        <asp:ListItem Text="Three" Value="ThreeM" />
    </asp:ListBox> 
    

    在后面的代码中

    foreach(ListItem listItem in lblMultiSelect.Items)
    {
       if (listItem.Selected == True)
       {
          var val = listItem.Value;
          var txt = listItem.Text; 
       }
    }
    

    否则选择带有复选框的下拉菜单

    jQuery Dropdown Check List

    System.Web.UI.WebControls.CheckBoxList

    【讨论】:

    • 我不需要一个 ListBox 我需要一个带有多个复选框的下拉菜单...有没有其他方法可以做到这一点???
    • 感谢您的帮助,如果列表框没有选择任何元素,我会用 javascript 检查另一个问题。如果它没有选择元素,我不会隐藏表格。而不是第一个我把这个工作: $ (document) .ready (function () { $ ('[id * = lblMultiSelect]'). multiselect ({ includeSelectAllOption: false, }); });
    • @IannaEttius 如果列表框中没有选择任何元素,您需要隐藏表格吗?当这种情况发生时..单击按钮或页面加载时?还显示表格的代码和所有
    • on page load the table is the same i just put the id and when selected item are none i wont to hide the table $('#table').hide ();
    • @IannaEttius 你什么时候想隐藏表格?我知道如果没有选择任何项目,它需要隐藏,但告诉我事件..是按钮点击还是什么..还告诉我你上面使用哪个控件来列出
    猜你喜欢
    • 1970-01-01
    • 2016-04-05
    • 1970-01-01
    • 1970-01-01
    • 2015-07-19
    • 1970-01-01
    • 2019-11-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多