บทช่วยสอน ASP.NET SortedList ที่ดีที่สุดในปี 2024 ในบทช่วยสอนนี้ คุณสามารถเรียนรู้ ลอง - ตัวอย่าง,วัตถุ SortedList,ข้อมูลผูกพัน,ตัวอย่าง,

ASP.NET SortedList

วัตถุ SortedList รวมคุณสมบัติของวัตถุและวัตถุ ArrayList ชัน HashTable


ตัวอย่าง

ลอง - ตัวอย่าง

SortedList RadioButtonList 1

SortedList RadioButtonList 2

SortedList DropDownList


วัตถุ SortedList

SortedList วัตถุมีรายการที่มีคีย์ / คู่ค่าที่แสดง SortedList วัตถุเรียงลำดับรายการตามลำดับตัวอักษรหรือตัวเลขการสั่งซื้อโดยอัตโนมัติ

โดยการเพิ่ม () วิธีการเพิ่มรายการ SortedList โดย TrimToSize () วิธีการปรับขนาด SortedList สุดท้าย

รหัสต่อไปนี้สร้างวัตถุ SortedList ที่เรียกว่า mycountries และเพิ่มธาตุทั้งสี่:

<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")
end if
end sub
</script>


ข้อมูลผูกพัน

วัตถุ SortedList จะสามารถสร้างข้อความและค่าสำหรับการควบคุมต่อไปนี้:

  • ASP: RadioButtonList
  • ASP: CheckBoxList
  • ASP: DropDownList
  • ASP: กล่องรายการ

การผูกข้อมูลเพื่อการควบคุม RadioButtonList แรกสร้างตัวควบคุม RadioButtonList ในเพจที่มีขอบ (ไม่ ASP ใดองค์ประกอบ ListItem):

<html>
<body>

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

</body>
</html>

แล้วเพิ่มสคริปต์เพื่อสร้างรายการและค่านิยมที่มีผลผูกพันในรายการเพื่อการควบคุม RadioButtonList:

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

<html>
<body>

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

</body>
</html>

จากนั้นเราก็เพิ่มย่อยเมื่อผู้ใช้คลิกที่รายการในการควบคุม RadioButtonList เมื่อ subroutine ที่จะดำเนินการ เมื่อปุ่มมีการคลิกที่ชื่อจะปรากฏในบรรทัดของข้อความ:

ตัวอย่าง

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

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

การสาธิต >>

ASP.NET SortedList
10/30