<%@ Page Language="C#" %><%@ Import Namespace="System.Data" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server"> void Page_Load(object sender, System.EventArgs e) { //创建Dataset对象 DataSet myDS = new DataSet(); //将 XML 文件读入 Dataset myDS.ReadXml(Server.MapPath("people.xml")); //显示 Dataset 中表的名称 Label1.Text = "表的名称是:" + myDS.Tables[0].TableName; //绑定到 DataGrid DataGrid1.DataSource = myDS.Tables[0]; DataGrid1.DataBind(); }</script>
<html xmlns="http://www.w3.org/1999/xhtml" ><head runat="server"> <title>将 XML 文件作为数据源绑定到控件</title></head><body> <form id="form1" runat="server"> <div> <h3>将 XML 文件作为数据源绑定到控件</h3> <asp:Label ID="Label1" runat="server">Label</asp:Label><br /> <asp:DataGrid ID="DataGrid1" runat="server"></asp:DataGrid> </div> </form></body></html>