最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

ASP.NET - Hashtable 對(duì)象

Hashtable 對(duì)象包含用鍵/值對(duì)表示的項(xiàng)目。

創(chuàng)建 Hashtable

Hashtable 對(duì)象包含用鍵/值對(duì)表示的項(xiàng)目。鍵被用作索引,通過(guò)搜索其鍵,可以實(shí)現(xiàn)對(duì)值的快速搜索。

通過(guò) Add() 方法向 Hashtable 添加項(xiàng)目。

下面的代碼創(chuàng)建一個(gè)名為 mycountries 的 Hashtable,并添加了四個(gè)元素:

<script runat="server">
Sub Page_Load
if Not Page.IsPostBack then
  dim mycountries=New Hashtable
  mycountries.Add("C","China")
  mycountries.Add("S","Sweden")
  mycountries.Add("F","France")
  mycountries.Add("I","Italy")
end if
end sub
</script>

數(shù)據(jù)綁定

Hashtable 對(duì)象可為下面這些控件自動(dòng)地生成文本和值:

  • asp:RadioButtonList
  • asp:CheckBoxList
  • asp:DropDownList
  • asp:Listbox

如需把數(shù)據(jù)綁定到某個(gè) RadioButtonList 控件,首先請(qǐng)?jiān)谝粋(gè) .aspx 頁(yè)面中創(chuàng)建 RadioButtonList 控件(沒有任何 asp:ListItem 元素)

<html>
<body>

<form runat="server">
<asp:RadioButtonList id="rb" runat="server" AutoPostBack="True" />
</form>

</body>
</html>

然后添加構(gòu)建列表的腳本:

<script runat="server">
sub Page_Load
if Not Page.IsPostBack then
  dim mycountries=New Hashtable
  mycountries.Add("C","China")
  mycountries.Add("S","Sweden")
  mycountries.Add("F","France")
  mycountries.Add("I","Italy")
  rb.DataSource=mycountries
  rb.DataValueField="Key"
  rb.DataTextField="Value"
  rb.DataBind()
end if
end sub
</script>

<html>
<body>

<form runat="server">
<asp:RadioButtonList id="rb" runat="server" AutoPostBack="True" />
</form>

</body>
</html>

然后我們添加一個(gè)子例程,該例程會(huì)在用戶點(diǎn)擊 RadioButtonList 控件中的某個(gè)項(xiàng)目時(shí)被執(zhí)行。當(dāng)某個(gè)單選按鈕被點(diǎn)擊,label 中會(huì)出現(xiàn)一條文本:

<script runat="server">
sub Page_Load
if Not Page.IsPostBack then
  dim mycountries=New Hashtable
  mycountries.Add("C","China")
  mycountries.Add("S","Sweden")
  mycountries.Add("F","France")
  mycountries.Add("I","Italy")
  rb.DataSource=mycountries
  rb.DataValueField="Key"
  rb.DataTextField="Value"
  rb.DataBind()
end if
end sub

sub displayMessage(s as Object,e As EventArgs)
lbl1.text="Your favorite country is: " & rb.SelectedItem.Text
end sub
</script>

<html>
<body>

<form runat="server">
<asp:RadioButtonList id="rb" runat="server"
AutoPostBack="True" onSelectedIndexChanged="displayMessage" />
<p><asp:label id="lbl1" runat="server" /></p>
</form>

</body>
</html>

顯示這個(gè)例子

注釋:您無(wú)法選擇添加到 Hashtable 的項(xiàng)目的排序方式。如需對(duì)項(xiàng)目進(jìn)行字母排序或數(shù)字排序,請(qǐng)使用 SortedList 對(duì)象。

商丘市| 定州市| 五指山市| 盐山县| 刚察县| 彭山县| 镇原县| 沁源县| 尖扎县| 海安县| 稻城县| 桂平市| 饶河县| 宁都县| 南平市| 青神县| 永兴县| 布拖县| 贺兰县| 抚松县| 宣威市| 肥城市| 林周县| 屏边| 泰宁县| 裕民县| 迁西县| 北海市| 中西区| 鲜城| 武川县| 浙江省| 新龙县| 旬阳县| 内丘县| 嵩明县| 贵南县| 建阳市| 财经| 屏东市| 安福县|