网络学院 w3pop社区 网络资源 IT新闻

w3pop.com :: 网络学院 :: ASP.NET :: ASP.NET - The SortedList Object 可排序列表对象

会员登陆

帐号

密码

回答

记住密码

忘记密码? 注册

ASP.NET
ASP.NET中 Bin,Ap..
C#中new和overrid..
ASP.NET 2.0 - Na..
ASP.NET 2.0 - Ma..
ASP.NET 2.0 新特..
ASP.NET - Databa..
ASP.NET - The Da..
ASP.NET - Repeat..
ASP.NET - XML 文..
ASP.NET - The So..
ASP.NET - The Ha..
ASP.NET - The Ar..
ASP.NET - Data B..
ASP.NET - 按钮控..
ASP.NET - TextBo..
ASP.NET 维持浏览..
ASP.NET Web 表单
ASP.NET - 事件
ASP.NET - 服务器..
asp.net的网页

ASP.NET - The SortedList Object 可排序列表对象


作者:w3schools 翻译/整理:w3pop.com 发布:2007-08-08 浏览:2033 :: ::

The SortedList object combines the features of both the ArrayList object and the Hashtable object.
可排序列表对象结合了数组列表对象以及哈希表对象的特点。


Examples 举例

Example 1 - SortedList RadioButtonList

Example 2 - SortedList RadiobuttonList

Example 3 - SortedList DropDownList


The SortedList Object
可排序列表对象

The SortedList object contains items in key/value pairs. A SortedList object automatically sort the items in alphabetic or numeric order.
可排序列表对象对象包含项目中的 键/值 对。可排序列表对象可自动的以字母或是数字来进行排序。

Items are added to the SortedList with the Add() method. A SortedList can be sized to its final size with the TrimToSize() method.
使用Add()方法可以将项目填加到可排序列表对象中。可排序列表可以使用TrimToSize()方法来将大小调整到最后的大小。

The following code creates a SortedList named mycountries and four elements are added:
下面的代码会建立一个可排序列表,名称为 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>

 


Data Binding
数据绑定

A SortedList object may automatically generate the text and values to the following controls:
可排序列表对象可以自动的给下面这些控件生成文字以及值:

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

To bind data to a RadioButtonList control, first create a RadioButtonList control (without any asp:ListItem elements) in an .aspx page:
要被 RadioButtonList 控件绑定数据,首先要在一个.aspx页面中建立 RadioButtonList 控件 (不需要任何asp:ListItem 元素):

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

Then add the script that builds the list:
然后加入脚本来生成列:

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

Then we add a sub routine to be executed when the user clicks on an item in the RadioButtonList control. When a radio button is clicked, a text will appear in a label:
然后我们加入子程序,当用户按下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 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>

评论 (0) All