📄 webform1.aspx.vb
字号:
Public Class WebForm1
Inherits System.Web.UI.Page
Protected WithEvents DDListName As System.Web.UI.WebControls.DropDownList
Protected WithEvents txtTitle As System.Web.UI.WebControls.TextBox
Protected WithEvents txtCompany As System.Web.UI.WebControls.TextBox
Protected WithEvents radioMarried As System.Web.UI.WebControls.RadioButton
#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
Class Contact
Dim _ID As Integer
Dim _name As String
Dim _title As String
Dim _company As String
Dim _married As Boolean
Property ID() As Integer
Get
ID = _ID
End Get
Set(ByVal Value As Integer)
_ID = Value
End Set
End Property
Property Name() As String
Get
Name = _name
End Get
Set(ByVal Value As String)
_name = Value
End Set
End Property
Property Title() As String
Get
Title = _title
End Get
Set(ByVal Value As String)
_title = Value
End Set
End Property
Property Company()
Get
Company = _company
End Get
Set(ByVal Value)
_company = Value
End Set
End Property
Property Married() As Boolean
Get
Married = _married
End Get
Set(ByVal Value As Boolean)
_married = Value
End Set
End Property
Public Overrides Function ToString() As String
Return (_name)
End Function
End Class
Dim Contacts As New ArrayList()
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
Dim c As New Contact()
c.ID = 0
c.Name = "Maria Anders"
c.Company = "Alfreds Futterkiste"
c.Title = "Sales Representative"
c.Married = False
Contacts.Add(c)
c = New Contact()
c.ID = 1
c.Name = "Ana Trujillo"
c.Company = "Ana Trujillo Emparedados y helados"
c.Title = "Owner"
c.Married = False
Contacts.Add(c)
c = New Contact()
c.ID = 2
c.Name = "Thomas Hardy"
c.Company = "Around the Horn"
c.Title = "Sales Representative"
c.Married = True
Contacts.Add(c)
c = New Contact()
c.ID = 3
c.Name = "Fr閐閞ique Citeaux"
c.Company = "Blondel p鑢e et fils"
c.Title = "Marketing Manager"
c.Married = False
Contacts.Add(c)
c = New Contact()
c.ID = 4
c.Name = "Elizabeth Brown"
c.Company = "Consolidated Holdings"
c.Title = "Sales Representative"
c.Married = True
Contacts.Add(c)
If Not Me.IsPostBack Then
DDListName.DataSource = Contacts
DDListName.DataTextField = "Name"
DDListName.DataValueField = "ID"
DDListName.DataBind()
End If
End Sub
Private Sub DDListName_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DDListName.SelectedIndexChanged
Dim selIndex As Integer
selIndex = DDListName.SelectedIndex
txtCompany.Text = CType(Contacts(DDListName.SelectedIndex), Contact).Company
txtTitle.Text = CType(Contacts(DDListName.SelectedIndex), Contact).Title
radioMarried.Checked = CType(Contacts(DDListName.SelectedIndex), Contact).Married
End Sub
End Class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -