asp.net Xml绑定到数据控件的具体实现
时间:2020-11-07 21:33:30|栏目:.NET代码|点击: 次
方法一: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();
}
}
复制代码 代码如下:
<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();
}
}
上一篇:C#简单的通用基础字典实现方法
栏 目:.NET代码
下一篇:C#中的char、string和StringBuilder的使用详解
本文地址:http://www.codeinn.net/misctech/19980.html