aspx:
- <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="aspnet._Default" %>
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml" >
- <head runat="server">
- <title>无标题页</title>
- <style type="text/css">
- .item
- {
- border:1px solid #369;
- }
- </style>
- </head>
- <body>
- <form id="form1" runat="server">
- <div>
- <asp:DataList ID="dlStudent" runat="server" RepeatColumns="2">
- <ItemTemplate>
- <div class="item"><%#Eval("name").ToString() %>-<%#Eval("age").ToString() %>-<%#Eval("sex").ToString() %>-<%#Eval("address").ToString() %></div>
- </ItemTemplate>
- </asp:DataList>
- </div>
- </form>
- </body>
- </html>
aspx.cs:
- using System;
- using System.Collections;
- using System.Configuration;
- using System.Data;
- using System.Linq;
- using System.Web;
- using System.Web.Security;
- using System.Web.UI;
- using System.Web.UI.HtmlControls;
- using System.Web.UI.WebControls;
- using System.Web.UI.WebControls.WebParts;
- using System.Xml.Linq;
- using System.Xml;
- using System.Data;
- namespace aspnet
- {
- public partial class _Default : System.Web.UI.Page
- {
- protected void Page_Load(object sender, EventArgs e)
- {
- if (!IsPostBack)
- {
- DataSet dsStudent = new DataSet();
- dsStudent.ReadXml(Server.MapPath("student.xml"));
- dlStudent.DataSource = dsStudent;
- dlStudent.DataBind();
- }
- }
- }
- }
student.xml:
- <?xml version="1.0" encoding="utf-8" ?>
- <students>
- <student>
- <name>张三</name>
- <age>23</age>
- <sex>男</sex>
- <address>山东省威海市环翠区</address>
- </student>
- <student>
- <name>赵敏</name>
- <age>22</age>
- <sex>女</sex>
- <address>北京市西城区</address>
- </student>
- <student>
- <name>李四</name>
- <age>21</age>
- <sex>男</sex>
- <address>山东省青岛市</address>
- </student>
- </students>
本文转自 xcf007 51CTO博客,原文链接:http://blog.51cto.com/xcf007/399230,如需转载请自行联系原作者