ASP NET – ArrayList 对象
来源:互联网 发布:ifconfig 设置mac 编辑:程序博客网 时间:2024/06/04 01:20
ArrayList 对象是包含单一数据值的项目的集合。
实例
ArrayList DropDownList
ArrayList RadioButtonList
创建 ArrayList
ArrayList 对象是包含单一数据值的项目的集合。
通过 Add() 方法向 ArrayList 添加项目。
下面的代码创建了一个新的 ArrayList 对象,名为 mycountries,并添加了四个项目:
<script runat="server">Sub Page_Loadif Not Page.IsPostBack then dim mycountries=New ArrayList mycountries.Add("China") mycountries.Add("Sweden") mycountries.Add("France") mycountries.Add("Italy")end ifend sub</script>
默认地,一个 ArrayList 对象包含 16 个条目。可通过 TrimToSize() 方法把 ArrayList 调整为最终大小:
<script runat="server">Sub Page_Loadif Not Page.IsPostBack then dim mycountries=New ArrayList mycountries.Add("China") mycountries.Add("Sweden") mycountries.Add("France") mycountries.Add("Italy") mycountries.TrimToSize()
end ifend sub</script>
通过 Sort() 方法,ArrayList 也能够按照字母顺序或者数字顺序进行排序:
<script runat="server">Sub Page_Loadif Not Page.IsPostBack then dim mycountries=New ArrayList mycountries.Add("China") mycountries.Add("Sweden") mycountries.Add("France") mycountries.Add("Italy") mycountries.TrimToSize() mycountries.Sort()
end ifend sub</script>
要实现颠倒的排序,请在 Sort() 方法后应用 Reverse() 方法:
<script runat="server">Sub Page_Loadif Not Page.IsPostBack then dim mycountries=New ArrayList mycountries.Add("China") mycountries.Add("Sweden") mycountries.Add("France") mycountries.Add("Italy") mycountries.TrimToSize() mycountries.Sort() mycountries.Reverse()
end ifend sub</script>
把数据绑定到 ArrayList
ArrayList 对象可向下面这些控件自动地生成文本和值:
- asp:RadioButtonList
- asp:CheckBoxList
- asp:DropDownList
- asp:Listbox
如需把数据绑定到一个 RadioButtonList 控件,首先请在一个 .aspx 页面中创建 RadioButtonList 控件(请注意,没有任何 asp:ListItem 元素):
<html><body><form runat="server"><asp:RadioButtonList id="rb" runat="server" /></form></body></html>
然后添加构建列表的脚本,并把列表中的值绑定到该 RadioButtonList 控件:
<script runat="server">Sub Page_Loadif Not Page.IsPostBack then dim mycountries=New ArrayList mycountries.Add("China") mycountries.Add("Sweden") mycountries.Add("France") mycountries.Add("Italy") mycountries.TrimToSize() mycountries.Sort() rb.DataSource=mycountries rb.DataBind()
end ifend sub</script><html><body><form runat="server"><asp:RadioButtonList id="rb" runat="server" /></form></body></html>
显示这个例子
RadioButtonList 控件的 DataSource 属性被设置为该 ArrayList,它定义了这个 RadioButtonList 控件的数据源。RadioButtonList 控件的 DataBind() 方法把 RadioButtonList 控件与数据源绑定在一起。
注释:数据值作为控件的 Text 和 Value 属性来使用。如需添加不同于 Text 的 Value,既可以使用 Hashtable 对象,也可以使用 SortedList 对象。
- ASP NET – ArrayList 对象
- ASP .NET - ArrayList对象
- ArrayList asp.net
- ArrayList-asp.net入门笔记
- ArrayList-asp.net入门笔记
- ASP.NET – Hashtable 对象
- ASP.NET – SortedList 对象
- asp.net 分割字符串,返回ArrayList格式
- ASP.NET Web Pages – 对象
- ASP.NET对象
- ASP.NET对象
- ASP.NET Command对象
- ASP.NET Request 对象
- ASP.NET Connection对象
- ASP .NET内部对象
- asp.net内置对象
- ASP.NET内置对象
- asp.net 内置对象
- 精通CSS 第四章 背景图片效果
- java导出Excel通用方法
- iframe与主框架跨域相互访问方法
- ibatis迁移mybatis详细方案(含脚本和注意事项)
- HTML基础
- ASP NET – ArrayList 对象
- JAVA 继承 父类子类 内存分配
- tomcat部署服务的四种方式
- ZZULIOJ【1072】青蛙爬井【循环】&&【模拟】
- SpringMVC最全约束
- 100. Same Tree
- OKHttp的配置及简单使用
- php中会话保持 session 与cooker
- gcc/g++中的pic与pie