ASP.NET - Hashtable taushe

Hashtable taushe yana ayyana abin da shida biyu.

a dadda yana, wanda zai saukiwa a koda a cikin koda.

Hashtable taushe yana ayyana abin da shida biyu. Kwanan yana ayyana daya a matsayin index, kuma zai iya ayyana kwallaye a cikin shida ta hanyar yin nazarin kwanan.

a dadda yana, wanda zai saukiwa a koda a cikin hashtable.

Koda baya ya cikin koda a cikin koda a yana ayyana hashtable mai sunan mycountries, wanda ya kama fara ayyana abin da shida biyu:

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

data binding

Hashtable taushe zai iya ayyana bayanin da kwallayen wa cikin wadannan shugaba:

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

donin a kama dukkanin bayanin zuwa shugaba RadioButtonList, kafin a ayyana shugaba a .aspx maiwatsarwa (wanda ba shi na asp:ListItem bukuku)

<html>
<body>
<form runat="server">
<asp:RadioButtonList id="rb" runat="server" AutoPostBack="True" />
</form>
</body>
</html>

kafin a dadda yana, wanda zai saukiwa a kiyarka a cikin ma'ajiza:

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

kafin a dadda yana, wanda zaiwa yaro na ya saukiwa a tukwasi shugaba RadioButtonList a cikin maiwatsarwa. lokaci baya wanda shugaba zai saukiwa, a label ya h�rɗa zai kai kalmoma:

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

Gani shafin shi

Rarrabawar:Ba za a iya zartar da hanyar tura zuwa Hashtable. domin ake zartar da tura a kan alama ko kuma a kan nau'in kanam, a samar da SortedList object.