The ListBox and DropDownList both are very useful for their own advantages. Their differences lie in their User Interfaces, DropDownList take less space but need more clicks to access while ListBox takes more space but provides everything itself on the page.
You can easily change the UI of a ListBox to DropdownList and vice versa. It may be useful to save the page height. It can be done in two ways.
Suppose the following code represents your ListBox & DropdownList
---------------------------------------------------------------
<asp:ListBox ID="ListBox1" runat="server" Rows="3">
< asp:ListItem>Option 1</asp:ListItem>
< asp:ListItem>Option 2</asp:ListItem>
< asp:ListItem>Option 3</asp:ListItem>
</ asp:ListBox>
< asp:DropDownList ID="DropDownList1" runat="server">
< asp:ListItem>Option 1</asp:ListItem>
< asp:ListItem>Option 2</asp:ListItem>
< asp:ListItem>Option 3</asp:ListItem>
</ asp:DropDownList>
1. From ServerSide (In c#)
To change ListBox to DropDownList just change the Rows property of the ListBox with “1” Then it will behave as the Dropdown list in UI.
→ ListBox1.Rows = 1;
For the reverse Add
→ DropDownList1.Attributes.Add("size", "3");