当前位置: 移动技术网 > IT编程>开发语言>.net > ASP.NET Web Forms - SortedList 对象

ASP.NET Web Forms - SortedList 对象

2017年12月22日  | 移动技术网IT编程  | 我要评论

三国麻将风云再次修改版,迪酷cs1.6cdkey,邻居吴姐

ASP.NET Web Forms- SortedList 对象

SortedList 对象结合了 ArrayList 对象和 Hashtable 对象的特性。

SortedList 对象

SortedList 对象包含用键/值对表示的项目。SortedList 对象按照字母顺序或者数字顺序自动地对项目进行排序。

通过 Add() 方法向 SortedList 添加项目。通过 TrimToSize() 方法把 SortedList 调整为最终尺寸。

下面的代码创建了一个名为 mycountries 的 SortedList 对象,并添加了四个元素:

数据绑定

SortedList 对象可为下列的控件自动生成文本和值:

AutoPostBack="True" onSelectedIndexChanged="displayMessage" />

asp:RadioButtonList

asp:CheckBoxList

asp:DropDownList

asp:Listbox

为了绑定数据到 RadioButtonList 控件,首先要在 .aspx 页面中创建一个 RadioButtonList 控件(不带任何 asp:ListItem 元素):

然后添加创建列表的脚本,并且绑定列表中的值到 RadioButtonList 控件:

然后我们添加一个子例程,当用户点击 RadioButtonList 控件中的某个项目时,该子例程会被执行。当某个单选按钮被点击时,label 中会出现一行文本。

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

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网