ASP.NET - Hashtable ¶ÔÏó
Hashtable ¶ÔÏó°üº¬Óüü/Öµ¶Ô±íʾµÄÏîÄ¿¡£
´´½¨ Hashtable
Hashtable ¶ÔÏó°üº¬Óüü/Öµ¶Ô±íʾµÄÏîÄ¿¡£¼ü±»ÓÃ×÷Ë÷Òý£¬Í¨¹ýËÑË÷Æä¼ü£¬¿ÉÒÔʵÏÖ¶ÔÖµµÄ¿ìËÙËÑË÷¡£
ͨ¹ý Add() ·½·¨Ïò Hashtable Ìí¼ÓÏîÄ¿¡£
ÏÂÃæµÄ´úÂë´´½¨Ò»¸öÃûΪ mycountries µÄ Hashtable£¬²¢Ìí¼ÓÁËËĸöÔªËØ£º
<script runat="server">
Sub Page_Load
if Not Page.IsPostBack then
dim mycountries=New Hashtable
mycountries.Add("C","China")
mycountries.Add("S","Sweden")
mycountries.Add("F","France")
mycountries.Add("I","Italy")
end if
end sub
</script>
Êý¾Ý°ó¶¨
Hashtable ¶ÔÏó¿ÉΪÏÂÃæÕâЩ¿Ø¼þ×Ô¶¯µØÉú³ÉÎı¾ºÍÖµ£º
- asp:RadioButtonList
- asp:CheckBoxList
- asp:DropDownList
- asp:Listbox
ÈçÐè°ÑÊý¾Ý°ó¶¨µ½Ä³¸ö RadioButtonList ¿Ø¼þ£¬Ê×ÏÈÇëÔÚÒ»¸ö .aspx Ò³ÃæÖд´½¨ RadioButtonList ¿Ø¼þ£¨Ã»ÓÐÈκΠasp:ListItem ÔªËØ£©
<html>
<body>
<form runat="server">
<asp:RadioButtonList id="rb" runat="server" AutoPostBack="True" />
</form>
</body>
</html>
È»ºóÌí¼Ó¹¹½¨ÁбíµÄ½Å±¾£º
<script runat="server"> sub Page_Load if Not Page.IsPostBack then dim mycountries=New Hashtable mycountries.Add("C","China") mycountries.Add("S","Sweden") mycountries.Add("F","France") mycountries.Add("I","Italy") rb.DataSource=mycountries rb.DataValueField="Key" rb.DataTextField="Value" rb.DataBind() end if end sub </script> <html> <body> <form runat="server"> <asp:RadioButtonList id="rb" runat="server" AutoPostBack="True" /> </form> </body> </html>
È»ºóÎÒÃÇÌí¼ÓÒ»¸ö×ÓÀý³Ì£¬¸ÃÀý³Ì»áÔÚÓû§µã»÷ RadioButtonList ¿Ø¼þÖеÄij¸öÏîĿʱ±»Ö´ÐС£µ±Ä³¸öµ¥Ñ¡°´Å¥±»µã»÷£¬label Öлá³öÏÖÒ»ÌõÎı¾£º
<script runat="server">
sub Page_Load
if Not Page.IsPostBack then
dim mycountries=New Hashtable
mycountries.Add("C","China")
mycountries.Add("S","Sweden")
mycountries.Add("F","France")
mycountries.Add("I","Italy")
rb.DataSource=mycountries
rb.DataValueField="Key"
rb.DataTextField="Value"
rb.DataBind()
end if
end sub
sub displayMessage(s as Object,e As EventArgs)
lbl1.text="Your favorite country is: " & rb.SelectedItem.Text
end sub
</script>
<html>
<body>
<form runat="server">
<asp:RadioButtonList id="rb" runat="server"
AutoPostBack="True" onSelectedIndexChanged="displayMessage" />
<p><asp:label id="lbl1" runat="server" /></p>
</form>
</body>
</html>
×¢ÊÍ£ºÄúÎÞ·¨Ñ¡ÔñÌí¼Óµ½ Hashtable µÄÏîÄ¿µÄÅÅÐò·½Ê½¡£ÈçÐè¶ÔÏîÄ¿½øÐÐ×ÖĸÅÅÐò»òÊý×ÖÅÅÐò£¬ÇëʹÓà SortedList ¶ÔÏó¡£