DropDownList VS ListBox selection Controls:
Listboxes and dropdowns are compact UI controls that allow users to select options. Listboxes
expose options right away and support multi-selection while dropdowns require a click to see
options and support only single-selection
Listboxes
In their simplest form, a listbox contains three main parts: a container box, a list of items, and
a label. Users can click on the items enclosed in the container box to select one or many from
the list. A listbox may scroll, depending on how many items it contains and the viewable area.
Sometimes, listboxes include checkboxes to clearly imply that multiselect functionality is
available. More complex listboxes allow users to resize the container box, reorder the list of
items, and make selections by moving items from one listbox to another.
There are 2 variations of listboxes that can be classified according to selection type. Each of
these listboxes can be scrollable or not.
Single-select listbox: With this type of listbox, users can select only one item from a list of
mutually exclusive options.
Multiselect listbox: Users can select or deselect one or more items by holding down
the Shift, Command, or Control key while clicking on items.
Example of listbox with selection of multiple items
Protected Sub ListBox1_SelectedIndexChanged(ByVal sender As Object, ByVal e As
System.EventArgs) Handles ListBox1.SelectedIndexChanged
Dim str As String
str = ""
Dim i As Integer
For i = 0 To ListBox1.Items.Count - 1
If ListBox1.Items(i).Selected = True Then
str &= ListBox1.Items(i).Value & ","
End If
Next
TextBox3.Text = str
End Sub
Copyright by Dr Ashoksinh Solanki(CASPS-2023) Subject:505-ASP.NET Page 1
Add and Remove Items from ListBox
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles
Button1.Click
'add iem in listbox
ListBox1.Items.Add("MCOM")
End Sub
Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Handles Button2.Click
'remove item
'ListBox1.Items.Remove("MCOM")
ListBox1.Items.RemoveAt(2)
End Sub
Dropdown Lists
In their simplest form, dropdown lists contain four main parts: a container box, a downward-
facing arrow button, a list of items, and a label. Users can click on the down-arrow to display a
list of mutually-exclusive items from which they can select only one. Like listboxes, dropdowns
may scroll depending on how many items they contain when expanded. With dropdown lists,
the selected option or default value remains visible in the container box, while the other list
items appear only after clicking on the down-arrow. Selecting an item or clicking outside of the
dropdown list will close it.
We can use ADD method to add items dynamically in selection boxes such as dropdown,
listbox as follows.
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles
Button1.Click
Copyright by Dr Ashoksinh Solanki(CASPS-2023) Subject:505-ASP.NET Page 2
'add item in listbox
ListBox1.Items.Add("MCOM")
End Sub
Add and Remove Items from DropDown
Protected Sub Button3_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles
Button3.Click
'add item in dropdown
DropDownList1.Items.Add("PURPLE")
End Sub
Protected Sub Button4_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Handles Button4.Click
'remove item from dropdown
DropDownList1.Items.Remove("BLACK")
End Sub
Copyright by Dr Ashoksinh Solanki(CASPS-2023) Subject:505-ASP.NET Page 3