当前位置: 首页 > 网络学院 > 服务端脚本教程 > ASP.NET > ASP.NET - XML 文件
We can bind an XML file to a list control.
我们可以将XML文件绑定到列表控件中。
Example 1 - XML RadiobuttonList
Here is an XML file named "countries.xml":
这是一个XML文件,名称为“countries.xml”:
<?xml version="1.0" encoding="ISO-8859-1"?> <countries> <country> <country> <country> <country> </countries> |
Take a look at the XML file: countries.xml
查看一下这个文件:countries.xml
First, import the "System.Data" namespace. We need this namespace to work with DataSet objects. Include the following directive at the top of an .aspx page:
首先,导入命名空间“System.Data”。我们需要这个命名空间来与数据集对象一起运作。在.aspx页面上顶部加入以下的指示:
<%@ Import Namespace="System.Data" %> |
Next, create a DataSet for the XML file and load the XML file into the DataSet when the page is first loaded:
接下来,为XML文件建立一个数据集并且当页面第一次加载的时候往数据集中载入XML文件:
<script runat="server"> |
To bind the DataSet to a RadioButtonList control, first create a RadioButtonList control (without any asp:ListItem elements) in an .aspx page:
将数据集绑定到RadioButtonList控件中,首先在.aspx页面中建立RadioButtonList控件:
<html> <form runat="server"> </body> |
Then add the script that builds the XML DataSet:
然后加入脚本来生成XML数据集:
<%@ Import Namespace="System.Data" %> <script runat="server"> <html> <form runat="server"> </body> |
Then we add a sub routine to be executed when the user clicks on an item in the RadioButtonList control. When a radio button is clicked, a text will appear in a label:
我们再往里加入子程序,当用户点击了RadioButtonList 控件里的项目后就会执行。当单选按钮被按下,就会在标签里出现文字:
<%@ Import Namespace="System.Data" %> <script runat="server"> sub displayMessage(s as Object,e As EventArgs) <html> <form runat="server"> </body> |