ASP.NET - XML ບັນດາຄວາມຄວາມສົມບູນ

ພວກເຈົ້າສາມາດປະສົງ XML ບັນດາຄວາມຄວາມສົມບູນໃຫ້ List ຄວາມຄວາມສົມບູນ.

ຄວາມຄວາມສົມບູນ

XML RadiobuttonList

ເອກະສານ XML

ມີເອກະສານ XML ຊື່ "countries.xml":

<?xml version="1.0" encoding="ISO-8859-1"?>
<countries>
<country>
  <text>China</text>
  <value>C</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

ປະສົງ DataSet ທີ່ List ຄວາມຄວາມສົມບູນ

ກໍາລັງ ອະໄວຍະການ "System.Data". ພວກເຈົ້າຕ້ອງການອະໄວຍະການນັ້ນກັບ DataSet ຄອມມູນຄ່າ. ກວດສອບຫລັງການສະເໜີນັ້ນໃນສຸດຂອງ .aspx ບົດແບບ:

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

ຫລັງຈາກນັ້ນ ສ້າງ DataSet ສຳລັບ ບັນດາ 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

ສະບັບພວກເຈົ້າຈະປະສົງ DataSet ທີ່ RadioButtonList ຄວາມຄວາມສົມບູນໃຫ້ ກໍສ້າງ RadioButtonList ຄວາມຄວາມສົມບູນໃນ .aspx ບົດແບບ (ບໍ່ມີ asp:ListItem ສິ່ມ):

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

ຫຼັງຈາກ, ພວກເຮົາສະໜອງອົງກອນລຳບາກ XML DataSet, ທີ່ຈະດຳເນີນງານສ້າງ.

<%@ 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>

ຫຼັງຈາກ, ພວກເຮົາສະໜອງອົງກອນລຳບາກບັນຊີ XML DataSet, ທີ່ຈະດຳເນີນງານຫຼັງຈາກຜູ້ນຳໃຊ້ຄົ້ນຫາຢ່າງໃນ RadioButtonList. ຄືວ່າຜູ້ນຳໃຊ້ຄົ້ນຫາຢ່າງໃນດາວຄົ້ນ, ຄວາມຕົກລົງຈະປະກອບເຂົ້າໃນ label:

<%@ 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>

ສະແດງຄວາມຍິງນີ້