方法一:aspx前台绑定
代码如下:
<asp:XmlDataSource ID="XmlDataSource1" runat="server" DataFile="~/SaveFile/test2.xml"></asp:XmlDataSource>
<asp:Repeater runat="server" ID="Rpt1" DataSourceID="XmlDataSource1">
<HeaderTemplate>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>ID</td>
<td>name</td>
<td>号码</td>
<td>date</td>
<td>CheckIn</td>
<td>CheckOut</td>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td><%# XPath("ID")%></td>
<td><%# XPath("name")%></td>
<td><%# XPath("号码")%></td>
<td><%# XPath("date")%></td>
<td><%# XPath("CheckIn")%></td>
<td><%# XPath("CheckOut")%></td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
方法二:绑定DataSource
aspx
代码如下:
<asp:Repeater runat="server" ID="Rpt1">
<HeaderTemplate>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>ID</td>
<td>name</td>
<td>号码</td>
<td>date</td>
<td>CheckIn</td>
<td>CheckOut</td>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td><%# Eval("ID")%></td>
<td><%# Eval("name")%></td>
<td><%# Eval("号码")%></td>
<td><%# Eval("date")%></td>
<td><%# Eval("CheckIn")%></td>
<td><%# Eval("CheckOut")%></td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
aspx.cs
代码如下:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
DataSet ds = new DataSet();
ds.ReadXml(Server.MapPath(@"~\SaveFile\test2.xml"));
Rpt1.DataSource = ds;
Rpt1.DataBind();
}
}