Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

asp.net

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.

like image 232
Er Jay Thakkar Avatar asked Sep 16 '13 09:09

Er Jay Thakkar


People also ask

How to Select multiple values in DropDownList in ASP net c#?

In order to implement a Multiple Select (MultiSelect) DropDownList with CheckBoxes in ASP.Net we will need to make use of ListBox control and apply the jQuery Bootstrap Multi-Select Plugin to it.

How to Select multiple Value in Drop down in ASP net?

The ASP.NET Core MultiSelect Dropdown is a quick replacement for the HTML select tag for selecting multiple values. HTML MultiSelect Dropdown is a textbox control that allows the user to type or select multiple values from a list of predefined options.

How do I select multiple items in a dropdown list?

For windows: Hold down the control (ctrl) button to select multiple options. For Mac: Hold down the command button to select multiple options.


3 Answers

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>
like image 54
Sachin Avatar answered Oct 17 '22 16:10

Sachin


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; 
       }
    }
like image 33
Christian Phillips Avatar answered Oct 17 '22 16:10

Christian Phillips


Dropdown list wont allows multiple item select in dropdown.

If you need , you can use listbox control..

ASP.NET List Box

like image 2
bgs Avatar answered Oct 17 '22 15:10

bgs