Click here to Skip to main content
15,888,461 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to do multiple selection in dropdownlist and display it in textbox.

What I have tried:

<asp:ListBox ID="lstSelect" runat="server" SelectionMode="Multiple">
<asp:ListItem Text="Mango" Value="1" />
<asp:ListItem Text="Apple" Value="2" />
<asp:ListItem Text="Banana" Value="3" />
Posted
Updated 30-Jul-16 22:43pm

1 solution

try this

ASP.NET
<asp:ListBox ID="lstSelect" runat="server" SelectionMode="Multiple" AutoPostBack="true" OnSelectedIndexChanged="lstSelect_SelectedIndexChanged">
            <asp:ListItem Text="Mango" Value="1" />
            <asp:ListItem Text="Apple" Value="2" />
            <asp:ListItem Text="Banana" Value="3" />
        </asp:ListBox>
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>

C#
protected void lstSelect_SelectedIndexChanged(object sender, EventArgs e)
      {
          string items = "";
          foreach (ListItem item in lstSelect.Items)
              if (item.Selected)
                  items += item.Text + ",";
          TextBox1.Text = items.Trim().TrimEnd(','); ;
      }
 
Share this answer
 
Comments
Member 12662265 31-Jul-16 4:52am    
Insted of ListBox Can we have DropdownList and do MultipleSelection and Display it in textbox?
Karthik_Mahalingam 31-Jul-16 4:55am    
how will you ?
asp:Dropdownlist is meant to select only one item in the list, to select multiple items we have to use listbox only.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900