Name

HtmlSelect

Synopsis

This class represents the HTML <select> tag, which allows the user to choose an option from a drop-down list box. To add an item to the list, use the Add() method of the Items property. The HtmlSelect control also supports data binding to its Items property.

To retrieve the currently selected item, you can use SelectedIndex property to find the ordinal number of the chosen item (-1 if no selection has been made), or the Value property to retrieve the text of the selected item. If you have set Multiple to True, more than one item may be selected and only the first item will be returned by the SelectedIndex and Value properties. Instead, you will have to iterate through the Items collection and check the System.Web.UI.WebControls.ListItem.Selected property for each one.

You can also react to the ServerChange event, which will fire only after a postback is triggered (for example, when the user clicks a submit button).

Public Class HtmlSelect : Inherits HtmlContainerControl : Implements_
       System.Web.UI.IPostBackDataHandler
' Public Constructors
   Public Sub New() 
' Public Instance Properties
   Overridable Public Property DataMember As String  
   Overridable Public Property DataSource As Object  
   Overridable Public Property DataTextField As String  
   Overridable Public Property DataValueField As String  
   Overrides Public Property InnerHtml As String  
   Overrides Public Property InnerText As String  
   Public ReadOnly Property Items As ListItemCollection  
   Public Property Multiple As ...

Get ASP.NET in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.