ASP.NET ArrayList 對象
ArrayList的對象是一個收集的項目包含一個單一的資料值。
建立一個ArrayList
ArrayList的對象是一個收集的項目包含一個單一的資料值。
項目被添加到該ArrayList與購買( )方法。
下面的代碼建立一個新的ArrayList對象命名mycountries和4個項目是補充說:
<script runat="server">
Sub Page_Load
if Not Page.IsPostBack then
dim mycountries=New ArrayList
mycountries.Add("Norway")
mycountries.Add("Sweden")
mycountries.Add("France")
mycountries.Add("Italy")
end if
end sub
</script>
預設情況下,一個ArrayList對象包含16個條目。一個ArrayList可以中小型其最終規模與TrimToSize ( )方法:
<script runat="server">
Sub Page_Load
if Not Page.IsPostBack then
dim mycountries=New ArrayList
mycountries.Add("Norway")
mycountries.Add("Sweden")
mycountries.Add("France")
mycountries.Add("Italy")
mycountries.TrimToSize()
end if
end sub
</script>
一個ArrayList也可以按字母順序進行排序或數值的排序( )方法:<script runat="server">
Sub Page_Load
if Not Page.IsPostBack then
dim mycountries=New ArrayList
mycountries.Add("Norway")
mycountries.Add("Sweden")
mycountries.Add("France")
mycountries.Add("Italy")
mycountries.TrimToSize()
mycountries.Sort()
end if
end sub
</script>排序次序相反,適用於逆向( )方法後,排序( )方法:<script runat="server">
Sub Page_Load
if Not Page.IsPostBack then
dim mycountries=New ArrayList
mycountries.Add("Norway")
mycountries.Add("Sweden")
mycountries.Add("France")
mycountries.Add("Italy")
mycountries.TrimToSize()
mycountries.Sort()
mycountries.Reverse()
end if
end sub
</script>一個ArrayList對象可以自動產生的文字和價值觀下列管制: 動態: RadioButtonList 動態: CheckBoxList 動態:下拉式清單動態:列表框綁定資料到RadioButtonList控制項,首先建立一個RadioButtonList控制項(無任何ASP : ListItem元素)的。 aspx頁:<html>
<body><form runat="server">
<asp:RadioButtonList id="rb" runat="server" />
</form></body>
</html>然後添加指令碼,建立名單,並結合中的值列表RadioButtonList控制項:<script runat="server">
Sub Page_Load
if Not Page.IsPostBack then
dim mycountries=New ArrayList
mycountries.Add("Norway")
mycountries.Add("Sweden")
mycountries.Add("France")
mycountries.Add("Italy")
mycountries.TrimToSize()
mycountries.Sort()
rb.DataSource=mycountries
rb.DataBind()
end if
end sub
</script><html>
<body><form runat="server">
<asp:RadioButtonList id="rb" runat="server" />
</form></body>
</html>該DataSource屬性的RadioButtonList控制項設定為ArrayList的,它定義了資料來源的RadioButtonList控制項。的DataBind ( )方法RadioButtonList控制項繫結資料源與RadioButtonList控制項。 註:資料值被用來作為兩種文字和Value屬性的控制。若要新增價值觀念不同的文字,可以使用雜湊表對象或SortedList對象。