ASP NET - ArrayList ¶ÔÏó

ArrayList ¶ÔÏóÊǰüº¬µ¥Ò»Êý¾ÝÖµµÄÏîÄ¿µÄ¼¯ºÏ¡£

ʵÀý

ArrayList DropDownList

ArrayList RadioButtonList

´´½¨ ArrayList

ArrayList ¶ÔÏóÊǰüº¬µ¥Ò»Êý¾ÝÖµµÄÏîÄ¿µÄ¼¯ºÏ¡£

ͨ¹ý Add() ·½·¨Ïò ArrayList Ìí¼ÓÏîÄ¿¡£

ÏÂÃæµÄ´úÂë´´½¨ÁËÒ»¸öÐ嵀 ArrayList ¶ÔÏó£¬ÃûΪ mycountries£¬²¢Ìí¼ÓÁËËĸöÏîÄ¿£º

<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>

ĬÈϵأ¬Ò»¸ö ArrayList ¶ÔÏó°üº¬ 16 ¸öÌõÄ¿¡£¿Éͨ¹ý TrimToSize() ·½·¨°Ñ ArrayList µ÷ÕûΪ×îÖÕ´óС£º

<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 Ò²Äܹ»°´ÕÕ×Öĸ˳Ðò»òÕßÊý×Ö˳Ðò½øÐÐÅÅÐò£º

<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>

ҪʵÏֵߵ¹µÄÅÅÐò£¬ÇëÔÚ Sort() ·½·¨ºóÓ¦Óà 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>

°ÑÊý¾Ý°ó¶¨µ½ ArrayList

ArrayList ¶ÔÏó¿ÉÏòÏÂÃæÕâЩ¿Ø¼þ×Ô¶¯µØÉú³ÉÎı¾ºÍÖµ£º

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

ÈçÐè°ÑÊý¾Ý°ó¶¨µ½Ò»¸ö RadioButtonList ¿Ø¼þ£¬Ê×ÏÈÇëÔÚÒ»¸ö .aspx Ò³ÃæÖд´½¨ RadioButtonList ¿Ø¼þ£¨Çë×¢Ò⣬ûÓÐÈκΠasp:ListItem ÔªËØ£©£º

<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("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>

ÏÔʾÕâ¸öÀý×Ó

RadioButtonList ¿Ø¼þµÄ DataSource ÊôÐÔ±»ÉèÖÃΪ¸Ã ArrayList£¬Ëü¶¨ÒåÁËÕâ¸ö RadioButtonList ¿Ø¼þµÄÊý¾ÝÔ´¡£RadioButtonList ¿Ø¼þµÄ DataBind() ·½·¨°Ñ RadioButtonList ¿Ø¼þÓëÊý¾ÝÔ´°ó¶¨ÔÚÒ»Æð¡£

×¢ÊÍ£ºÊý¾ÝÖµ×÷Ϊ¿Ø¼þµÄ Text ºÍ Value ÊôÐÔÀ´Ê¹Óá£ÈçÐèÌí¼Ó²»Í¬ÓÚ Text µÄ Value£¬¼È¿ÉÒÔʹÓà Hashtable ¶ÔÏó£¬Ò²¿ÉÒÔʹÓà SortedList ¶ÔÏó¡£