最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

ASP NET - ArrayList 對(duì)象

ArrayList 對(duì)象是包含單一數(shù)據(jù)值的項(xiàng)目的集合。

實(shí)例

ArrayList DropDownList

ArrayList RadioButtonList

創(chuàng)建 ArrayList

ArrayList 對(duì)象是包含單一數(shù)據(jù)值的項(xiàng)目的集合。

通過 Add() 方法向 ArrayList 添加項(xiàng)目。

下面的代碼創(chuàng)建了一個(gè)新的 ArrayList 對(duì)象,名為 mycountries,并添加了四個(gè)項(xiàng)目:

<script runat="server">
Sub Page_Load
if Not Page.IsPostBack then
  dim mycountries=New ArrayList
  mycountries.Add("China")
  mycountries.Add("Sweden")
  mycountries.Add("France")
  mycountries.Add("Italy")
end if
end sub
</script>

默認(rèn)地,一個(gè) ArrayList 對(duì)象包含 16 個(gè)條目?赏ㄟ^ TrimToSize() 方法把 ArrayList 調(diào)整為最終大。

<script runat="server">
Sub Page_Load
if Not Page.IsPostBack then
  dim mycountries=New ArrayList
  mycountries.Add("China")
  mycountries.Add("Sweden")
  mycountries.Add("France")
  mycountries.Add("Italy")
  mycountries.TrimToSize()
end if
end sub
</script>

通過 Sort() 方法,ArrayList 也能夠按照字母順序或者數(shù)字順序進(jìn)行排序:

<script runat="server">
Sub Page_Load
if Not Page.IsPostBack then
  dim mycountries=New ArrayList
  mycountries.Add("China")
  mycountries.Add("Sweden")
  mycountries.Add("France")
  mycountries.Add("Italy")
  mycountries.TrimToSize()
  mycountries.Sort()
end if
end sub
</script>

要實(shí)現(xiàn)顛倒的排序,請(qǐng)?jiān)?Sort() 方法后應(yīng)用 Reverse() 方法:

<script runat="server">
Sub Page_Load
if Not Page.IsPostBack then
  dim mycountries=New ArrayList
  mycountries.Add("China")
  mycountries.Add("Sweden")
  mycountries.Add("France")
  mycountries.Add("Italy")
  mycountries.TrimToSize()
  mycountries.Sort()
  mycountries.Reverse()
end if
end sub
</script>

把數(shù)據(jù)綁定到 ArrayList

ArrayList 對(duì)象可向下面這些控件自動(dòng)地生成文本和值:

  • asp:RadioButtonList
  • asp:CheckBoxList
  • asp:DropDownList
  • asp:Listbox

如需把數(shù)據(jù)綁定到一個(gè) RadioButtonList 控件,首先請(qǐng)?jiān)谝粋(gè) .aspx 頁(yè)面中創(chuàng)建 RadioButtonList 控件(請(qǐng)注意,沒有任何 asp:ListItem 元素):

<html>
<body>

<form runat="server">
<asp:RadioButtonList id="rb" runat="server" />
</form>

</body>
</html>

然后添加構(gòu)建列表的腳本,并把列表中的值綁定到該 RadioButtonList 控件:

<script runat="server">
Sub Page_Load
if Not Page.IsPostBack then
  dim mycountries=New ArrayList
  mycountries.Add("China")
  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>

顯示這個(gè)例子

RadioButtonList 控件的 DataSource 屬性被設(shè)置為該 ArrayList,它定義了這個(gè) RadioButtonList 控件的數(shù)據(jù)源。RadioButtonList 控件的 DataBind() 方法把 RadioButtonList 控件與數(shù)據(jù)源綁定在一起。

注釋:數(shù)據(jù)值作為控件的 Text 和 Value 屬性來使用。如需添加不同于 Text 的 Value,既可以使用 Hashtable 對(duì)象,也可以使用 SortedList 對(duì)象。

镇宁| 元谋县| 车险| 太湖县| 铜山县| 新邵县| 南昌县| 九龙城区| 邹城市| 宜阳县| 澜沧| 微博| 大新县| 天镇县| 高青县| 克东县| 曲沃县| 永靖县| 东乌| 高碑店市| 灵璧县| 宁夏| 皮山县| 车致| 兴海县| 福安市| 舞钢市| 陇南市| 新泰市| 昔阳县| 云林县| 海安县| 曲周县| 南充市| 丹阳市| 城市| 崇州市| 临邑县| 竹溪县| 门源| 肇东市|