Latest web development tutorials
×

ASP.NET หลักสูตร

ASP.NET หลักสูตร ASP.NET แนะนำโดยย่อ

WP หลักสูตร

WebPages แนะนำโดยย่อ WebPages Razor WebPages แบบ WebPages โฟลเดอร์ WebPages สถานการณ์โดยรวม WebPages ฟอร์ม WebPages วัตถุ WebPages ไฟล์ WebPages ผู้ช่วย WebPages WebGrid WebPages แผนภูมิ WebPages Email 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 TextBox WebForms Button WebForms ข้อมูลผูกพัน WebForms ArrayList WebForms Hashtable WebForms SortedList WebForms XML ไฟล์ WebForms Repeater WebForms DataList WebForms เชื่อมต่อฐานข้อมูล WebForms หน้าเว็บมาสเตอร์ WebForms การเดินเรือ WebForms ตัวอย่าง

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

WebForms HTML WebForms Controls WebForms Validation

ASP.NET ArrayList

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


ตัวอย่าง

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

ArrayList DropDownList

ArrayList RadioButtonList


สร้าง ArrayList

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

การเพิ่มรายการ ArrayList ผ่านทางเพิ่ม () วิธีการ

รหัสต่อไปนี้จะสร้างวัตถุ 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 รายการ โดย TrimToSize () วิธีการปรับขนาด ArrayList สุดท้าย:

<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 สามารถอยู่ในลำดับตัวอักษรหรือคำสั่งที่เป็นตัวเลขเรียงลำดับโดย:

<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) วิธีการ:

<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 ในเพจที่มีขอบ (ไม่ ASP ใดองค์ประกอบ 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 ควบคุม RadioButtonList ของ DataBind () วิธีการของการควบคุม RadioButtonList ผูกแหล่งข้อมูล

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