ASP.NETのArrayList2024 年の最新の入門チュートリアル。このコースでは 試してみてください - 例,ArrayListの作成,ArrayListにデータをバインド,例, について学習できます。
ASP.NETのArrayList
個々のデータ値項目のコレクションを含むArrayListのオブジェクト。
試してみてください - 例
ArrayListのDropDownListコントロール
ArrayListのRadioButtonListの
ArrayListの作成
個々のデータ値項目のコレクションを含むArrayListのオブジェクト。
追加()メソッドを介してArrayListにアイテムを追加します。
次のコードは、mycountriesという名前のArrayListオブジェクトを作成し、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のエントリが含まれています。 TrimToSize()メソッドによって、最終的なサイズの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()
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>
ソート()メソッドReverse()メソッドの後、逆の並べ替えを達成するために:
<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にデータをバインド
ArrayListのオブジェクトは自動的に次のコントロールのテキストと値を生成することができます。
- ASP:RadioButtonListの
- ASP:CheckBoxListの
- ASP:DropDownListコントロール
- ASP:リストボックス
RadioButtonListコントロールにデータをバインドし、最初の(任意のASPなし:ListItemの要素).aspxページにRadioButtonListコントロールを作成するには:
<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>
デモ>> RadioButtonListのコントロールのDataSourceプロパティは、RadioButtonListコントロールのデータソースを定義するのArrayListに設定されています。 RadioButtonListコントロールのRadioButtonListのコントロールのDataBindを()メソッドは、データソースをバインドします。
注意:使用するコントロールのTextとValueプロパティとしてデータ値を。値を追加するには、テキストとは異なり、HashtableオブジェクトまたはSortedListのオブジェクトを使用してください。