asp.net.ph

Skip Navigation Links

DropDownList Control Syntax

ASP.NET Syntax   ASP.NET Syntax for Web Controls


Enables users to select from a single-selection drop-down list. The drop-down portion can contain any number of list items.

Declarative Syntax

For information on the individual members of this class, see DropDownList in the class library.

Remarks

The DropDownList control renders a single selection drop-down list control. You can control the appearance of the DropDownList control by setting the BorderColor, BorderStyle, and BorderWidth properties.

To specify the items that you want to appear in the DropDownList control, place a ListItem element for each entry between the opening and closing tags of the DropDownList control.

The DropDownList control also supports data binding. To bind the control to a data source, first create a data source, such as a System.Collections.ArrayList object, that contains the items to display in the control. Next, use the Control.DataBind method to bind the data source to the DropDownList control. The DropDownList control will now display the information from the data source.

Use the SelectedIndex property to programmatically determine the index of the item selected by the user from the DropDownList control.

Syntax Example

The below code snippet demonstrates how to use the DropDownList control.

<html>
<head>
<script language="C#" runat="server">
   void Button_Click ( Object sender, EventArgs e ) {
      msgLabel.Text = "You selected: " +
         DropDownList1.SelectedItem.Text + ".";
   }
</script>
</head>
<body>
   <form runat="server">
      <h3>DropDownList Example</h3>
      Select an item from the list and click the submit button.
      <p>
      <asp:DropDownList id="DropDownList1" runat="server">
         <asp:ListItem>Item 1</asp:ListItem>
         <asp:ListItem>Item 2</asp:ListItem>
         <asp:ListItem>Item 3</asp:ListItem>
         <asp:ListItem>Item 4</asp:ListItem>
      </asp:DropDownList>
      <br><br>
      <asp:Button id="Button1"
         Text = "Submit"
         onClick = "Button_Click"
         runat="server" />
      <br><br>
      <asp:Label id="msgLabel" runat="server" />
   </form>
</body>
</html>
  C# VB

See Also

DropDownList Class   DropDownList Web Server Control



© 2025 Reynald Nuñez and asp.net.ph. All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note