ASP.NET - SortedList Object

ວັດຖຸ SortedList ມີທາງພາຍຫຼັງທາງວັດຖຸ ArrayList ແລະ Hashtable.

ວັດຖຸ SortedList

ວັດຖຸ SortedList ມີປະສົມປະກອບທີ່ຕາມຄຳສັ່ງຄູ່/ຄູ່ມູນ. ວັດຖຸ SortedList ສາມາດຈັດການຂອງບັນດາປະກອບຈາກວິທີການຈັດການຄຳສັ່ງຄູ່ມູນຫຼືຄຳສັ່ງຄູ່ມູນ.

ການເພີ່ມບັນດາປະກອບໄປໃນ SortedList ຜ່ານວິທີການ Add(). SortedList ສາມາດດັດແປງຂອງຂອບເຂດຈາກວິທີການ TrimToSize().

ລະຫັດການທີ່ລົງຄາວັດຖຸ SortedList ຊື່ວ່າ mycountries ແລະເພີ່ມສິບສີ່ບັນດາປະກອບ:

<script runat="server">
sub Page_Load
if Not Page.IsPostBack then
  dim mycountries=New SortedList
  mycountries.Add("C","China")
  mycountries.Add("S","Sweden")
  mycountries.Add("F","France")
  mycountries.Add("I","Italy")
end if
end sub
</script>

ການມັດຂໍ້ມູນ

ວັດຖຸ SortedList ສາມາດສ້າງຂໍ້ຄວາມແລະຄູ່ມູນສຳລັບພາດຄວາມທີ່ຢູ່ໃຫ້ໃນນັ້ນຢ່າງອັນຕະລາຍ:

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

ສຳລັບທີ່ຈະມັດຂໍ້ມູນຫາ ຄວາມຄິດເລືອກ Radio Button List 控件ແລ້ວກໍ່ຕ້ອງສ້າງ ຄວາມຄິດເລືອກ Radio Button List 控件ໃນເອສບິກ ບໍ່ມີສິນລະເບີດ 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 SortedList
  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. ເວລາທີ່ປະກອບສີ່ປະກອບຖືກເລືອກ, ຄວາມຂຽນຈະປະກອບໃນ label:

<script runat="server">
sub Page_Load
if Not Page.IsPostBack then
  dim mycountries=New SortedList
  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>

ສະແດງການຄົ້ນຄວ້ານີ້