中国搜 程序源代码学习 编程源代码 直接应用在编程实践中 优秀编程书籍源码欣赏

收藏本页到>> 新浪ViVi  365Key网摘   IE收藏夹 |设为首页

 中国搜首页 >>ASP.NET相关>>RadioButtonList数据绑定 C#版

代码说明:把RadioButtonList绑定到诸如数据表或现有的集合这样的数据源。下面的程序在Page_Load子程序中,创建了一个colArrayList的ArrayList,并且把Red Blue和Green值添加到其中。接着,把该ArrayList赋值给RadioButtonList控件的DataSource属性,并且调用DataBind()方法。在该方法被调用后,ArrayList中所有的数据项被加载到RadioButtonList的ListItemCollection集合中。ArryList是一个集合,可以看作是一个没有固定大小的数组。

<Script Runat="Server">

Sub Page_Load
Dim colArrayList As New ArrayList
If Not IsPostBack Then
colArrayList.Add( "Red" )
colArrayList.Add( "Blue" )
colArrayList.Add( "Green" )
radlFavoriteColor.DataSource = colArrayList
radlFavoriteColor.DataBind()
End If
End Sub

</Script>

<html>
<head><title>RadioButtonListDataBind.aspx</title></head>
<body>

<form Runat="Server">

<asp:RadioButtonList
ID="radlFavoriteColor"
Runat="Server"/>

</form>

</body>
</html>

   运行演示程序   

  ©2004   www.zhonguosou.com