当前位置: 首页 > 网络学院 > 服务端脚本教程 > ASP.NET > ASP.NET - The ArrayList Object(数组列表对象)
The ArrayList object is a collection of items containing a single data value.
数组列表对象为一组包含单一数据值的集合。
Example 1 - ArrayList RadioButtonList [数组列表 - 单选按钮列表]
Example 2 - ArrayList DropDownList [ 数组列表 - 下拉列表 ]
The ArrayList object is a collection of items containing a single data value.
数组列表对象为一组包含单一数据值的集合。
Items are added to the ArrayList with the Add() method.
使用数组列表中的Add()方法可加入内容。
The following code creates a new ArrayList object named mycountries and four items are added:
以下代码将会建立一个名为mycountries的数组列表并填加进四项内容:
<script runat="server"> |
By default, an ArrayList object contains 16 entries. An ArrayList can be sized to its final size with the TrimToSize() method:
默认情况下,一个数组列表对象会包含16个条目。可以使用TrimToSize()这个方法来确定数组列表它的最终大小:
<script runat="server"> |
An ArrayList can also be sorted alphabetically or numerically with the Sort() method:
数组列表还可以通过Sort()方法来选择是依据字母或是数字来进行排列:
<script runat="server"> |
To sort in reverse order, apply the Reverse() method after the Sort() method:
在Sort()方法后应用Reverse()以逆序的形式排列:
<script runat="server"> |
An ArrayList object may automatically generate the text and values to the following controls:
数组列表可在以下控件中字生成文字以及值:
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> <form runat="server"> </body> |
Then add the script that builds the list and binds the values in the list to the RadioButtonList control:
然后加入脚本给RadioButtonList控件生成列表并绑上数据:
<script runat="server"> <html> <form runat="server"> </body> |
The DataSource property of the RadioButtonList control is set to the ArrayList and it defines the data source of the RadioButtonList control. The DataBind() method of the RadioButtonList control binds the data source with the RadioButtonList control.
RadioButtonList 控件的 DataSource(数据源)在数组列表中进行了设置并且它定义了RadioButtonList控件的数据源。RadioButtonList控件通过使用DataBind()方法将数据源和控件进行绑定
Note: The data values are used as both the Text and Value properties for the control. To add Values that are different from the Text, use either the Hashtable object or the SortedList object.
注意:数据值即可作为控件的Text(显示文字)也可以是Value(值)。要加入的值与显示文字有点区别,可以使用Hashtable 或是 SortedList 对象。