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

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รูปแบบเว็บ - SortedList วัตถุ


วัตถุ SortedList รวมคุณสมบัติของทั้งวัตถุ ArrayList และวัตถุ Hashtable


ตัวอย่าง

ตัวอย่าง

SortedList RadioButtonList 1

SortedList DropDownList


วัตถุ 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("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 (ไม่มีงูเห่าใดองค์ประกอบ 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("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 เมื่อปุ่มมีการคลิกที่ข้อความจะปรากฏในป้ายกำกับ:

ตัวอย่าง

<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>
แสดงตัวอย่าง»