Select multiple value in DropDownList using ASP.NET and C#

后端 未结 4 1471
南方客
南方客 2020-12-06 09:16

Select multiple value in DropDownList using ASP.NET and C#. I tried it to select single value from drop down but unable to find multiple selection.

相关标签:
4条回答
  • 2020-12-06 09:44

    For multiple selection dropdown list,cannot accomplish it directly using dropdown..Can be done in similar ways..

    Either you have to use checkbox list or listbox (ajax inclusive)

    http://www.codeproject.com/Articles/55184/MultiSelect-Dropdown-in-ASP-NET

    http://social.msdn.microsoft.com/Forums/vstudio/en-US/54374df7-5a54-42bc-83b8-ad5994cb634d/multi-select-dropdownlist

    http://www.dotnetfunda.com/articles/article1591-multiselect-dropdownlist-in-aspnet-using-csharp-40-.aspx

    0 讨论(0)
  • 2020-12-06 09:46

    Take a look at the ListBox control to allow multi-select.

    <asp:ListBox runat="server" ID="lblMultiSelect" SelectionMode="multiple">
                <asp:ListItem Text="opt1" Value="opt1" />
                <asp:ListItem Text="opt2" Value="opt2" />
                <asp:ListItem Text="opt3" Value="opt3" />
    </asp:ListBox> 
    

    in the code behind

    foreach(ListItem listItem in lblMultiSelect.Items)
        {
           if (listItem.Selected)
           {
              var val = listItem.Value;
              var txt = listItem.Text; 
           }
        }
    
    0 讨论(0)
  • 2020-12-06 09:51

    Dropdown list wont allows multiple item select in dropdown.

    If you need , you can use listbox control..

    ASP.NET List Box

    0 讨论(0)
  • 2020-12-06 10:00

    In that case you should use ListBox control instead of dropdown and Set the SelectionMode property to Multiple

    <asp:ListBox runat="server" SelectionMode="Multiple" >
      <asp:ListItem Text="test1"></asp:ListItem>
      <asp:ListItem Text="test2"></asp:ListItem>
      <asp:ListItem Text="test3"></asp:ListItem>
    </asp:ListBox>
    
    0 讨论(0)
提交回复
热议问题