A commonly used C# web control is the DropDownList. A DropDownList allow a web user to select from a set of items. Each selectable item has a text field (which the web user sees) plus a hidden value field for programming purposes. In MicrosoftVisual Studio 2008, adding a DropDownList is simple via drag and drop from the toolbox under the Standard section.
To add items to your DropDownList via the Designer view, navigate to the Properties of the DropDownList. Under the Misc section, click Items. You will see a button with an ellipses. Clicking that button opens a dialog box that lists the current items. The options for each items are Enabled, Selected, Text, Value.
- Enabled – Whether or not to display the item in the DropDownList.
- Selected – Whether or not the item is selected by default.
- Text – The string as it appears in the DropDownList.
- Value – This is not displayed in the DropDownList, but can be uncovered by viewing a webpage’s source.
Note that if more than one item for any single DropDownList is selected, Visual Studio will display an error in the Designer view, but will not give any compile time errors or warnings. An error will however appear at runtime.
Below is the source example of a DropDownList with three items where item A is selected by default:
<asp:DropDownList ID="DropDownList1" runat="server">
<asp:ListItem Value="1" Selected="True">A</asp:ListItem>
<asp:ListItem Value="2">B</asp:ListItem>
<asp:ListItem Value="3">C</asp:ListItem>
</asp:DropDownList>
RSS Feed
Posted in
Tags: 
