Web Controls
Part II
List Controls
• ListBox
• DropDownList
• CheckBoxList
• RadioButtonList
• BulletedList (Not selectable)
• Properties of Selectable List Controls
– SelectedIndex
– SelectedItem
• Properties of ListItem
– Text
– Value
– Selected
2
Multiple Select List Controls
• ListBox
– SelectionMode=ListSelectionMode.Multiple
• RadioButtonList
• DropDownList
• CheckBoxList
3
Example: Use of CheckBoxList
• Display a list of options with checkboxes.
• Display a command button.
• When the user clicks the command button the selected options are
listed in a separate control.
• Required Web Control Classes
– CheckBoxList
– Button
– Label
4
5
6
7
8
9
Table Controls
10
Example: Use of Table Controls
Create a table with x rows and y columns dynamically.
11
12
13
14
15
Page_Load
' Configure the table's appearance.
' This could also be performed in the .aspx file,
' or in the cmdCreate_Click event handler.
tbl.BorderStyle = BorderStyle.Inset
tbl.BorderWidth = Unit.Pixel(1)
16
cmdCreate.Click
tbl.Controls.Clear()
Dim i, j As Integer
For i = 0 To Val(txtRows.Text - 1)
Dim rowNew As New TableRow()
tbl.Controls.Add(rowNew)
For j = 0 To Val(txtCols.Text - 1)
Dim cellNew As New TableCell()
Dim lblNew As New Label()
lblNew.Text = "Example Cell (" & i.ToString() & "," & j.ToString() & ")<br>"
Dim imgNew As New System.Web.UI.WebControls.Image()
imgNew.ImageUrl = "cellpic.png"
cellNew.Controls.Add(lblNew)
cellNew.Controls.Add(imgNew)
If chkBorder.Checked = True Then
cellNew.BorderStyle = BorderStyle.Inset
cellNew.BorderWidth = Unit.Pixel(1)
End If
rowNew.Controls.Add(cellNew)
Next
Next
17