Senarai Isih Borang Web
Objek SortedList menggabungkan ciri objek ArrayList dan objek Hashtable.
Cubalah - Contoh
SortedList RadiobuttonList 1
SortedList RadiobuttonList 2
SortedList
DropDown List 🎜 >Objek SortedListObjek SortedList mengandungi item yang diwakili oleh pasangan kunci/nilai. Objek SortedList secara automatik mengisih item dalam susunan abjad atau berangka. Tambah item pada SortedList melalui kaedah Add(). Laraskan SortedList kepada saiz akhir melalui kaedah TrimToSize(). Kod berikut mencipta objek SortedList bernama mycountries dan menambah empat elemen:
<script runat="server">
sub Page_Load
if Not Page .IsPostBack kemudian
, dim mycountries=New SortedList
, mycountries.Add("N","Norway")
, mycountries.Add("S","Sweden")
, mycountries.Tambah("F","Perancis")
, mycountries.Add("I","Italy")
end if
end sub
</script>
if Not Page .IsPostBack kemudian
, dim mycountries=New SortedList
, mycountries.Add("N","Norway")
, mycountries.Add("S","Sweden")
, mycountries.Tambah("F","Perancis")
, mycountries.Add("I","Italy")
end if
end sub
</script>
data binding
Objek SortedList boleh menjana teks dan nilai secara automatik untuk kawalan berikut:
- asp:RadioButtonListasp:CheckBoxListasp:DropDownList
- asp:Listbox
<html>
Jalankan instance»
<body>
<form runat="server">
<asp:RadioButtonList id="rb" runat="server" AutoPostBack="True" />
</form>
</body>
</html>
<form runat="server">
<asp:RadioButtonList id="rb" runat="server" AutoPostBack="True" />
</form>
</body>
</html>
Kemudian tambah skrip yang mencipta senarai dan ikat nilai dalam senarai ke kawalan RadioButtonList:
<script runat="server">
sub Page_Load
jika Bukan Halaman.IsPostBack maka
, dim mycountries=New SortedList
, mycountries.Add("N","Norway")
, mycountries.Add("S","Sweden")
, mycountries.Tambah("F","Perancis")
, mycountries.Add("I","Itali")
, rb.DataSource=mycountries
, rb.DataValueField="Kunci"
, rb.DataTextField="Nilai"
, rb.DataBind()
end if
end sub
</script>
<html>
<body>
<form runat ="server">
<asp:RadioButtonList id="rb" runat="server" AutoPostBack="True" />
</form>
</body>
</html>
sub Page_Load
jika Bukan Halaman.IsPostBack maka
, dim mycountries=New SortedList
, mycountries.Add("N","Norway")
, mycountries.Add("S","Sweden")
, mycountries.Tambah("F","Perancis")
, mycountries.Add("I","Itali")
, rb.DataSource=mycountries
, rb.DataValueField="Kunci"
, rb.DataTextField="Nilai"
, rb.DataBind()
end if
end sub
</script>
<html>
<body>
<form runat ="server">
<asp:RadioButtonList id="rb" runat="server" AutoPostBack="True" />
</form>
</body>
</html>
Kemudian kami menambah subcontoh Ini subrutin akan dilaksanakan apabila pengguna mengklik item dalam kawalan RadioButtonList. Apabila butang radio diklik, baris teks akan muncul dalam label:
Instance
<script runat="server"> sub Page_Load if Not Page.IsPostBack then dim mycountries=New SortedList mycountries.Add("N","Norway") 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> <!DOCTYPE html> <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>
Jalankan instance»
Klik butang "Jalankan Instance" untuk melihat contoh dalam talian