ASP.NET ArrayList
ArrayList วัตถุที่มีคอลเลกชันของรายการค่าข้อมูลส่วนบุคคล
ลอง - ตัวอย่าง
สร้าง ArrayList
ArrayList วัตถุที่มีคอลเลกชันของรายการค่าข้อมูลส่วนบุคคล
การเพิ่มรายการ ArrayList ผ่านทางเพิ่ม () วิธีการ
รหัสต่อไปนี้จะสร้างวัตถุ ArrayList ชื่อ mycountries และเพิ่มสี่รายการ:
Sub Page_Load
if Not Page.IsPostBack then
dim mycountries=New ArrayList
mycountries.Add("Norway")
mycountries.Add("Sweden")
mycountries.Add("France")
mycountries.Add("Italy")
end if
end sub
</script>
โดยค่าเริ่มต้นวัตถุ ArrayList มี 16 รายการ โดย TrimToSize () วิธีการปรับขนาด ArrayList สุดท้าย:
Sub Page_Load
if Not Page.IsPostBack then
dim mycountries=New ArrayList
mycountries.Add("Norway")
mycountries.Add("Sweden")
mycountries.Add("France")
mycountries.Add("Italy")
mycountries.TrimToSize()
end if
end sub
</script>
โดยเรียง () วิธีการ ArrayList สามารถอยู่ในลำดับตัวอักษรหรือคำสั่งที่เป็นตัวเลขเรียงลำดับโดย:
Sub Page_Load
if Not Page.IsPostBack then
dim mycountries=New ArrayList
mycountries.Add("Norway")
mycountries.Add("Sweden")
mycountries.Add("France")
mycountries.Add("Italy")
mycountries.TrimToSize()
mycountries.Sort()
end if
end sub
</script>
เพื่อให้เกิดการจัดเรียงย้อนกลับหลังจากเรียง () วิธีการ (Reverse) วิธีการ:
Sub Page_Load
if Not Page.IsPostBack then
dim mycountries=New ArrayList
mycountries.Add("Norway")
mycountries.Add("Sweden")
mycountries.Add("France")
mycountries.Add("Italy")
mycountries.TrimToSize()
mycountries.Sort()
mycountries.Reverse()
end if
end sub
</script>
ข้อมูลที่ผูกกับ ArrayList
วัตถุ ArrayList จะสามารถสร้างข้อความและค่าสำหรับการควบคุมต่อไปนี้:
- ASP: RadioButtonList
- ASP: CheckBoxList
- ASP: DropDownList
- ASP: กล่องรายการ
การผูกข้อมูลเพื่อการควบคุม RadioButtonList แรกสร้างตัวควบคุม RadioButtonList ในเพจที่มีขอบ (ไม่ ASP ใดองค์ประกอบ ListItem):
<body>
<form runat="server">
<asp:RadioButtonList id="rb" runat="server" />
</form>
</body>
</html>
แล้วเพิ่มสคริปต์เพื่อสร้างรายการและค่านิยมที่มีผลผูกพันในรายการเพื่อการควบคุม RadioButtonList:
ตัวอย่าง
Sub Page_Load
if Not Page.IsPostBack then
dim mycountries=New ArrayList
mycountries.Add("Norway")
mycountries.Add("Sweden")
mycountries.Add("France")
mycountries.Add("Italy")
mycountries.TrimToSize()
mycountries.Sort()
rb.DataSource=mycountries
rb.DataBind()
end if
end sub
</script>
<html>
<body>
<form runat="server">
<asp:RadioButtonList id="rb" runat="server" />
</form>
</body>
</html>
การสาธิต >>
RadioButtonList คุณสมบัติของตัวควบคุมแหล่งข้อมูลการตั้งค่าเพื่อ ArrayList ซึ่งกำหนดแหล่งข้อมูลของการควบคุม RadioButtonList ควบคุม RadioButtonList ของ DataBind () วิธีการของการควบคุม RadioButtonList ผูกแหล่งข้อมูล
หมายเหตุ: ค่าข้อมูลเป็นข้อความและมูลค่าทรัพย์สินของการควบคุมที่จะใช้ซึ่งแตกต่างจากข้อความเพื่อเพิ่มมูลค่าโปรดใช้ Hashtable วัตถุหรือวัตถุ SortedList