YearOfBirth.xml
复制代码 代码如下:
使用一个属性来获取这个文档:
复制代码 代码如下:
private string XmlFile
{
get
{
return Server.MapPath("~/YearOfBirth.xml");
}
}
在aspx网页上拉一个RadioButtonList控件,用来显示XML的数据。
复制代码 代码如下:
接下来,用DataSet去读取刚才写好的获取XML文件的属性。
复制代码 代码如下:
View Code
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Default3 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
Data_Binding();
}
private void Data_Binding()
{
using (DataSet ds = new DataSet())
{
ds.ReadXml(XmlFile);
this.RadioButtonListYearOfBirth.DataSource = ds;
this.RadioButtonListYearOfBirth.DataTextField = "Name";
this.RadioButtonListYearOfBirth.DataValueField = "ID";
this.RadioButtonListYearOfBirth.DataBind();
}
}
}
网页运行效果:



