| 代码说明:把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>
|