(3)把XML文檔通過DataSet讀入到Repeater中.
你也可把它讀入到DataSet.原理是一樣的.
<%@ Import Namespace="System" %>
< %@ Import Namespace="System.IO" %>
< %@ Import Namespace="System.Data" %>
< %@ Page Language="C#" %>
< Html>
< head>
< title>讀入到Repeater</title>
< script language="C#" runat=server>
public void Page_Load(Object obj,EventArgs e)
{
string xpath="db/people.XML" ;
try
{
DataSet ds= new DataSet();
FileStream fs= new FileStream(Server.MapPath(xpath),FileMode.Open,FileAccess.Read,FileShare.ReadWrite) ;
ds.ReadXML(new StreamReader(fs));
fs.Close();
Trace.Warn("表記錄數",Convert.ToString(ds.Tables[0].Rows.Count));
MyDataList.DataSource=ds.Tables[0].DefaultVIEw;
MyDataList.DataBind();
}
catch (Exception ed)
{
Response.Write("<font color=#FF0000>"+ed.ToString()+"</font>") ;
}
}
< /script>
< /head>
< body >
< ASP:Repeater id="MyDataList" runat="server">
< headertemplate>
< h5> VIEwer Details </h5>
< /headertemplate>
< itemtemplate>
< br>
< table class="mainheads" width="60%" style="font: 8pt verdana" >
< tr style="background-color:#FFFFCC">
< td>name:</td>
< td><%# DataBinder.Eval(Container.DataItem, "name") %></td>
< /tr>
< tr style="background-color:#FFFFCC">
< td>title:</td>
< td><%# DataBinder.Eval(Container.DataItem, "title")%></td>
< /tr>
< tr style="background-color:#FFFFCC">
< td>title2:</td>
< td><%# DataBinder.Eval(Container.DataItem, "title2") %></td>
< /tr>
< /table><br>
< /itemtemplate>
< /ASP:Repeater>
< /body>
< /Html>
---------