Imports System
Imports System.Collections
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Web
Imports System.Web.SessionState
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.HtmlControls
Namespace ASPAuthors.aspnetbyexample.ch05
Public Class DropDownListVB
Inherits System.Web.UI.Page
Protected WithEvents Dropdownlist2 As System.Web.UI.WebControls.DropDownList
Protected WithEvents Dropdownlist3 As System.Web.UI.WebControls.DropDownList
Protected WithEvents DropDownList1 As System.Web.UI.WebControls.DropDownList
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
End Sub
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub
#End Region
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If Not Page.IsPostBack Then
' Programmatic Adding
Dropdownlist2.Items.Add("One")
Dropdownlist2.Items.Add(new ListItem("Two","2"))
Dropdownlist2.Items.Insert(0,"") ' Add a blank item to the top
' Create a data source
Dim AL As New ArrayList()
AL.Add("One")
AL.Add("Two")
' Set values using databinding
Dropdownlist3.DataSource = AL
Dropdownlist3.DataBind()
' Set selected item to "Two"
Dropdownlist3.Items.FindByText("Two").Selected = true
End If
End Sub
End Class
End Namespace