Difference between DropDownList and ListBox in ASP.NET

 Posted by Poster on 2/4/2010 | Category: ASP.NET Interview questions | Views: 39099
Answer:

The basic difference between DropDownList and ListBox in ASP.NET are following

1. Only one items of DropDownList is visible when it renders on the page. More than one item of the ListBox is visible when it renders on the page.
2. Only one item can be selected in DropDownList. More than one item can be selected in Listbox provided SelectionMode is Multiple as in the below code snippets.

Both controls are rendered as "<select>" html tag in the HTML.

DROPDOWNLIST
<asp:DropDownList ID="drop1" runat="server">

<asp:ListItem Text="One" Value="1" />
<asp:ListItem Text="Two" Value="2" />
</asp:DropDownList>


For more details on DropDownList click http://www.dotnetfunda.com/tutorials/controls/dropdownlist.aspx

LIST BOX
 <asp:ListBox ID="list1" runat="server" SelectionMode="Multiple">

<asp:ListItem Text="One" Value="1" />
<asp:ListItem Text="Two" Value="2" />
</asp:ListBox>


For more details on ListBox click http://www.dotnetfunda.com/tutorials/controls/listbox.aspx

Thank you.


Asked In: Many Interviews | Alert Moderator 

Comments or Responses

Login to post response