System.Web.UI.WebControls Namespace DropDownList Class
Initializes a new instance of the DropDownList class.
[ VB ]
Public Sub New ( )
[ C# ]
public DropDownList ( );
[ C++ ]
public: DropDownList ( );
[ JScript ]
public function DropDownList ( );
When using this constructor to instantiate a new instance of the DropDownList control, the ListItem and ListItemCollection classes are also used. The ListItem control stores the item content whereas the ListItemCollection allows it to be added to the DropDownList control.
The following example demonstrates how to initialize a new instance of the DropDownList class.
void Page_Load ( Object src, EventArgs e ) {
if ( !IsPostBack ) {
ArrayList myListItems = new ArrayList ( );
myListItems.Add ( "Item 1" );
myListItems.Add ( "Item 2" );
myListItems.Add ( "Item 3" );
myListItems.Add ( "Item 4" );
myListItems.Add ( "Item 5" );
DropDownList myList = new DropDownList ( );
Page.Controls.Add ( myList )
myList.DataSource = myListItems;
myList.DataBind ( );
}
}
Sub Page_Load ( src As Object, e As EventArgs )
If Not IsPostBack Then
Dim myListItems As New ArrayList ( )
myListItems.Add ( "Item 1" )
myListItems.Add ( "Item 2" )
myListItems.Add ( "Item 3" )
myListItems.Add ( "Item 4" )
myListItems.Add ( "Item 5" )
Dim myList As New DropDownList ( )
Page.Controls.Add ( myList )
myList.DataSource = myListItems
myList.DataBind ( )
End If
End Sub |
|
C# |
VB |
DropDownList Members