?? 5-4.aspx
字號:
<html>
<head>
<title>
ListBox控件實例
</title>
</head>
<script language="VB" runat=server>
Sub Page_Load()
'如果選中黑體復選控件,把文本標簽的字體設為黑體
If chkBold.Checked
lblTxt.font.bold=True
Else
lblTxt.font.bold=False
End If
'如果選中多選的單選控件,那么則把列表框設為允許多選
If rbtnMulti.Checked
list1.SelectionMode=ListSelectionMode.Multiple
Else
list1.SelectionMode=ListSelectionMode.Single
End If
If Not IsPostBack
'第一次請求時,為列表框設置數據
Dim values as ArrayList=new ArrayList()
values.add("北京")
values.add("上海")
values.add("廣州")
values.add("香港")
list1.datasource=values
list1.databind
Else
'把從列表框選中的內容賦予文本標識,如果未選擇,顯示"未選擇"
Dim i as int32
Dim tmpStr as String
'對列表框list1的items集合輪詢,根據其Selected屬性,判斷是否被選中
For i=0 to list1.items.count-1
If list1.items(i).selected
tmpStr=tmpStr & " " & list1.items(i).text
End If
Next
If tmpStr is Nothing
tmpStr="未選擇"
End If
lblTxt.text="您選中的項為: " & tmpStr
End If
End Sub
</script>
<body >
<center>
<h2>ListBox控件實例</h2>
<hr>
<form method="POST" runat=server>
請選擇城市
<br>
<asp:ListBox id="list1" runat=server/>
<br>
<asp:CheckBox id="chkBold" text="黑體" runat=server />
<br>
<asp:RadioButton id="rbtnSingle" Checked=True text="單項選擇"
groupname="group1" runat=server />
<asp:RadioButton id="rbtnMulti" text="多項選擇"
groupname="group1" runat=server />
<br>
<asp:button text="提交" runat=server />
<hr>
<asp:label id="lblTxt" runat=server />
</form>
</center>
</body>
</html>
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -