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

ASP.NET - Hashtable 對象

Hashtable 對象包含用鍵/值對表示的項目。

創(chuàng)建 Hashtable

Hashtable 對象包含用鍵/值對表示的項目。鍵被用作索引,通過搜索其鍵,可以實現對值的快速搜索。

通過 Add() 方法向 Hashtable 添加項目。

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

<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>

數據綁定

Hashtable 對象可為下面這些控件自動地生成文本和值:

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

如需把數據綁定到某個 RadioButtonList 控件,首先請在一個 .aspx 頁面中創(chuàng)建 RadioButtonList 控件(沒有任何 asp:ListItem 元素)

<html>
<body>

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

</body>
</html>

然后添加構建列表的腳本:

<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>

然后我們添加一個子例程,該例程會在用戶點擊 RadioButtonList 控件中的某個項目時被執(zhí)行。當某個單選按鈕被點擊,label 中會出現一條文本:

<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>

顯示這個例子

注釋:您無法選擇添加到 Hashtable 的項目的排序方式。如需對項目進行字母排序或數字排序,請使用 SortedList 對象。

青川县| 乌拉特中旗| 庄浪县| 门头沟区| 南通市| 韶关市| 蚌埠市| 郯城县| 麻城市| 德格县| 黄平县| 西安市| 西吉县| 白银市| 新晃| 绍兴县| 南乐县| 烟台市| 广德县| 宁津县| 金华市| 贺兰县| 巴中市| 抚州市| 繁昌县| 土默特右旗| 顺昌县| 呼和浩特市| 沁源县| 平度市| 康保县| 凤山县| 尚义县| 东安县| 东城区| 江口县| 汪清县| 新丰县| 林芝县| 岢岚县| 安徽省|