(2) viewguestbook.aspx:
< %@ page language="c#" % >
< %@ import namespace="system" % >
< %@ import namespace="system.io" % >
< %@ import namespace="system.data" % >
< %-- 以上是所需的名字空间 --% >
< html >
< head >
< title >欢迎来到我的留言簿< /title >
< script language="c#" runat=server >
//页面下载完毕后,运行这个脚本
public void page_load(object sender, eventargs e)
{
//包含所有数据的xml文件的路径
//如果你的路径和下面的不同,则请修改
string datafile = "db/guest.xml" ;
//运用一个try-catch块完成信息读取功能
try
{
//建立一个数据集对象
dataset guestdata = new dataset();
//为数据库文件打开一个filestream
filestream fin ;
fin = new filestream(server.mappath(datafile),filemode.open,
fileaccess.read,fileshare.readwrite) ;
//把数据库中内容读到数据集中
guestdata.readxml(fin);
fin.close();
//将第一个表中的数据集付给repeater
mydatalist.datasource = guestdata.tables[0].defaultview;
mydatalist.databind();
}
catch (exception edd)
{
//捕捉异常
errmess.text="不能从xml文件读入数据,原因:"+edd.tostring() ;
}
}
< /script >
< link href="mystyle.css" type=text/css rel=stylesheet >
< /head >
< body topmargin="0" leftmargin="0" marginwidth="0" marginheight="0" rightmargin="0" >
< !-- #include file="header.inc" -- >
< asp:label id="errmess" text="" style="color:#ff0000" runat="server" / >
< br >
< h3 align="center" class="newsbody" >我的留言簿< /h3 >
< asp:repeater id="mydatalist" runat="server" >
< headertemplate >
< table class="mainheads" width="100%" style="font: 8pt verdana" >
< tr style="background-color:#ff9966" >
< th >
姓名
< /th >
< th >
国家
< /th >
< th >
email
< /th >
< th >
留言
< /th >
< th >
日期/时间
< /th >
< /tr >
< /headertemplate >
< itemtemplate >
< tr style="background-color:#ffffff" >
< td >
< %# databinder.eval(container.dataitem, "name") % >
< /td >
< td >
< %# databinder.eval(container.dataitem, "country") % >
< /td >
< td >
< %# databinder.eval(container.dataitem, "email") % >
< /td >
< td >
< %# databinder.eval(container.dataitem, "comments") % >
< /td >
< td >
< %# databinder.eval(container.dataitem, "datetime") % >
< /td >
< /tr >
< /itemtemplate >
< footertemplate >
< /table >
< /footertemplate >
< /asp:repeater >
< !-- #include file="footer.inc" -- > < /body >< /html >
Java Asp PHP .Net XML C/C++ CGI VB Jsp J2ee J2se J2me EJB Servlet Tomcat Resin Struts Weblogic Eclipse ANT GUI JMS Web servise IDEA Webphere Hibernate Spring Jboss Applet Swing Socket Javamail Perl Ajax P2P 安全 模式 框架 测试 开源 游戏
Windows XP Windows 2000 Windows 2003 Windows Me Windows 9.x Linux UNIX 注册表 操作系统 服务器 应用服务器