ล่าสุดการพัฒนาเว็บบทเรียน
×

ASP.NET เกี่ยวกับการสอน

ASP.NET บ้าน ASP.NET แนะนำ

WP เกี่ยวกับการสอน

WebPages แนะนำ WebPages มีดโกน WebPages แบบ WebPages โฟลเดอร์ WebPages สถานการณ์โดยรวม WebPages ฟอร์ม WebPages วัตถุ WebPages ไฟล์ WebPages ฐานข้อมูล WebPages ผู้ช่วย WebPages WebGrid WebPages ชาร์ต WebPages อีเมล์ WebPages PHP WebPages ประกาศ WebPages ตัวอย่าง

WP คู่มืออ้างอิง

WebPages ชั้นเรียน WebPages ความปลอดภัย WebPages ฐานข้อมูล WebPages เว็บเมล์ WebPages ผู้ช่วย

ASP.NET Razor

Razor แนะนำ Razor วากยสัมพันธ์ Razor C# ตัวแปร Razor C# ลูป Razor C# ตรรกะ Razor VB ตัวแปร Razor VB ลูป Razor VB ตรรกะ

ASP.NET MVC

MVC แนะนำ MVC ใบสมัคร MVC โฟลเดอร์ MVC แบบ MVC ตัวควบคุม MVC เข้าชม MVC ฐานข้อมูล MVC แบบ MVC ความปลอดภัย MVC HTML ผู้ช่วย MVC ประกาศ MVC การอ้างอิง

WF สอน

WebForms แนะนำ WebForms หน้า WebForms การควบคุม WebForms เหตุการณ์ WebForms ฟอร์ม WebForms ViewState WebForms กล่องข้อความ WebForms ปุ่ม WebForms ข้อมูลผูกพัน WebForms ArrayList WebForms Hashtable WebForms SortedList WebForms XML ไฟล์ WebForms Repeater WebForms DataList WebForms DbConnection WebForms Master หน้า WebForms การเดินเรือ WebForms ตัวอย่าง


 

ASP.NETรูปแบบเว็บ - วัตถุ ArrayList


วัตถุ ArrayList คือชุดของรายการที่มีค่าข้อมูลเดียว


ตัวอย่าง

ตัวอย่าง

ArrayList DropDownList

ArrayList RadioButtonList


สร้าง ArrayList

วัตถุ ArrayList คือชุดของรายการที่มีค่าข้อมูลเดียว

รายการที่จะเพิ่มให้กับ ArrayList ที่มี Add() วิธีการ

รหัสต่อไปนี้จะสร้างวัตถุ ArrayList ชื่อ mycountries ใหม่และสี่มีการเพิ่มรายการ:

<script runat="server">
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 รายการ ArrayList สามารถปรับขนาดให้มีขนาดเป็นครั้งสุดท้ายกับ TrimToSize() วิธีการ:

<script runat="server">
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 ยังสามารถเรียงลำดับตัวอักษรหรือตัวเลขที่มี Sort() วิธีการ:

<script runat="server">
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() วิธีการหลังจากที่ Sort() วิธีการ:

<script runat="server">
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 (ไม่มีงูเห่าใดองค์ประกอบ ListItem) ในหน้าขอบ:

<html>
<body>

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

</body>
</html>

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

ตัวอย่าง

<script runat="server">
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 DataBind() วิธีการของการควบคุม RadioButtonList ผูกแหล่งข้อมูลที่มีการควบคุม RadioButtonList

Note: ค่าข้อมูลที่ถูกนำมาใช้เป็นทั้งข้อความและมูลค่าคุณสมบัติสำหรับการควบคุม ในการเพิ่มค่านิยมที่แตกต่างจากข้อความที่ใช้ทั้ง Hashtable วัตถุหรือวัตถุ SortedList