net入門教程:ASP.NET ArrayList 對象

來源:互聯網
上載者:User

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對象。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.