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

ข้อมูล XML ASP.NET ผูกพัน

เราสามารถผูกไฟล์ XML เพื่อควบคุมรายการ


ไฟล์ XML

มีไฟล์ชื่อ "countries.xml" ไฟล์ XML คือ:

<?xml version="1.0" encoding="ISO-8859-1"?>

<countries>

<country>
<text>Norway</text>
<value>N</value>
</country>

<country>
<text>Sweden</text>
<value>S</value>
</country>

<country>
<text>France</text>
<value>F</value>
</country>

<country>
<text>Italy</text>
<value>I</value>
</country>

</countries>

ตรวจสอบไฟล์ XML: countries.xml


ชุดข้อมูลเชื่อมโยงกับรายชื่อการควบคุม

ครั้งแรกที่นำเข้า "System.Data" namespace เราจำเป็นต้อง namespace นี้จะทำงานร่วมกับชุดข้อมูลวัตถุ การเรียนการสอนต่อไปนี้จะรวมอยู่ในด้านบนของหน้าขอบนี้:

<%@ Import Namespace="System.Data" %>

ถัดไปสร้างชุดข้อมูลสำหรับไฟล์ XML และเมื่อโหลดแรกหน้านี้ XML โหลดไฟล์ชุดข้อมูล:

<script runat="server">
sub Page_Load
if Not Page.IsPostBack then
dim mycountries=New DataSet
mycountries.ReadXml(MapPath("countries.xml"))
end if
end sub

การผูกข้อมูลเพื่อการควบคุม RadioButtonList แรกสร้างตัวควบคุม RadioButtonList ในเพจที่มีขอบ (ไม่ ASP ใดองค์ประกอบ ListItem):

<html>
<body>

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

</body>
</html>

แล้วเพิ่มสคริปต์เพื่อสร้างชุดข้อมูล XML และผูกค่ากับการควบคุม XML ชุดข้อมูล RadioButtonList:

<%@ Import Namespace="System.Data" %>

<script runat="server">
sub Page_Load
if Not Page.IsPostBack then
dim mycountries=New DataSet
mycountries.ReadXml(MapPath("countries.xml"))
rb.DataSource=mycountries
rb.DataValueField="value"
rb.DataTextField="text"
rb.DataBind()
end if
end sub
</script>

<html>
<body>

<form runat="server">
<asp:RadioButtonList id="rb" runat="server"
AutoPostBack="True" onSelectedIndexChanged="displayMessage" />
</form>

</body>
</html>

จากนั้นเราก็เพิ่มย่อยเมื่อผู้ใช้คลิกที่รายการในการควบคุม RadioButtonList เมื่อ subroutine ที่จะดำเนินการ เมื่อปุ่มมีการคลิกที่ชื่อจะปรากฏในบรรทัดของข้อความ:

ตัวอย่าง

<%@ Import Namespace="System.Data" %>

<script runat="server">
sub Page_Load
if Not Page.IsPostBack then
dim mycountries=New DataSet
mycountries.ReadXml(MapPath("countries.xml"))
rb.DataSource=mycountries
rb.DataValueField="value"
rb.DataTextField="text"
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>

การสาธิต >>