asp.net入門教程:ASP.NET SortedList 對象教程
SortedList對象的特點相結合的ArrayList的對象和雜湊表對象。
範例
例如1 -S ortedListR adioButtonList
例如2 -S ortedListR adiobuttonList
例如3 -S ortedList下拉式清單
在SortedList對象
在SortedList對象包含項目的鍵/值對。阿SortedList自動排序對象中的項目字母或數字順序。
項目新增至SortedList與購買( )方法。阿SortedList尺寸可作其最後大小與TrimToSize ( )方法。
下面的代碼建立了一個SortedList命名mycountries和四個要素說:
<script runat="server">
sub Page_Load
if Not Page.IsPostBack then
dim mycountries=New SortedList
mycountries.Add("N","Norway")
mycountries.Add("S","Sweden")
mycountries.Add("F","France")
mycountries.Add("I","Italy")
end if
end sub
</script>
資料繫結阿SortedList對象可自動產生的文字和價值觀下列管制: 動態: 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 SortedList
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 SortedList
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>