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

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


วัตถุ Hashtable มีรายการในคีย์ / คู่ค่า


ตัวอย่าง

ตัวอย่าง

Hashtable RadioButtonList 1

Hashtable DropDownList


สร้าง Hashtable

วัตถุ Hashtable มีรายการในคีย์ / คู่ค่า คีย์จะถูกใช้เป็นดัชนีและการค้นหาอย่างรวดเร็วมากสามารถทำค่าโดยการค้นหาผ่านกุญแจ

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

รหัสต่อไปนี้จะสร้าง Hashtable ชื่อ mycountries และธาตุทั้งสี่ที่มีการเพิ่ม:

<script runat="server">
Sub Page_Load
if Not Page.IsPostBack then
  dim mycountries=New Hashtable
  mycountries.Add("N","Norway")
  mycountries.Add("S","Sweden")
  mycountries.Add("F","France")
  mycountries.Add("I","Italy")
end if
end sub
</script>

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

วัตถุ Hashtable อาจสร้างข้อความและค่าที่จะควบคุมต่อไปนี้โดยอัตโนมัติ:

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

การผูกข้อมูลเพื่อการควบคุม RadioButtonList แรกสร้างตัวควบคุม RadioButtonList (without any asp:ListItem elements) ในหน้าขอบ:

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

Note: คุณไม่สามารถเลือกการเรียงลำดับของรายการที่เพิ่มให้กับ Hashtable การเรียงลำดับรายการตามลำดับตัวอักษรหรือตัวเลขใช้วัตถุ SortedList