当前位置: 首页 > 网络学院 > 服务端脚本教程 > ASP.NET > ASP.NET - The SortedList Object 可排序列表对象

ASP.NET
ASP.NET 介绍
ASP 和 ASP.NET 之间的区别
asp.net的安装
asp.net的网页
ASP.NET - 服务器控件
ASP.NET - 事件
ASP.NET Web 表单
ASP.NET 维持浏览状态
ASP.NET - TextBox(文本框)控件
ASP.NET - 按钮控件
ASP.NET - Data Binding(数据绑定)
ASP.NET - The ArrayList Object(数组列表对象)
ASP.NET - The Hashtable Object 哈希表对象
ASP.NET - The SortedList Object 可排序列表对象
ASP.NET - XML 文件
ASP.NET - Repeater Control 转发器控件
ASP.NET - The DataList Control 数据列表控件
ASP.NET - Database Connection 数据库连接
ASP.NET 2.0 新特征
ASP.NET 2.0 - Master Pages 控制页[主页]

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


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-03-01   浏览: 992 ::
收藏到网摘: n/a

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

登陆 | 还没注册?