net入門教程:ASP.NET Hashtable 對象 教程

來源:互聯網
上載者:User

ASP.NET Hashtable 對象 教程

在雜湊表對象包含項目的鍵/值對。

看個例子.

<script  runat="server">
sub Page_Load
if Not Page.IsPostBack then
   dim mycountries=New Hashtable
   mycountries.Add("N","Norway")
   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>


建立一個雜湊表
在雜湊表對象包含項目的鍵/值對。把鑰匙是用來作為指標,並很快搜尋可以用於搜尋的價值通過他們的鑰匙。

項目被添加到雜湊表與購買( )方法。

下面的代碼建立一個雜湊表命名mycountries和四個要素說:

<script runat="server">
Sub Page_Load
if Not Page.IsPostBack then
  dim mycountries=New Hashtable
  mycountries.Add("N","Norway")
  mycountries.Add("S","Sweden")
  mycountries.Add("F","France")
  mycountries.Add("I","Italy")
end if
end sub
</script>
資料繫結阿雜湊表對象可自動產生的文字和價值觀下列管制: 動態: RadioButtonList 動態: CheckBoxList 動態:下拉式清單動態:列表框綁定資料到RadioButtonList控制項,首先建立一個RadioButtonList控制項(無任何ASP : ListItem元素)的。 aspx頁:<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("N","Norway")
  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控制項。當一個選項按鈕被點擊,一個文本將出現在一個標籤:<script runat="server">
sub Page_Load
if Not Page.IsPostBack then
  dim mycountries=New Hashtable
  mycountries.Add("N","Norway")
  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 subsub 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>注意:您不能選擇的排序次序的項目增加了雜湊表。項目分類按字母順序或數值,使用SortedList對象。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.