NewsRhzhi | 先创资讯 | 旧版入口
rhzhi.net
网站首页 | NewsRhzhi | 先创资讯 | 操作系统 | 工具软件 | 办公软件 | 网站设计 | 组网专栏 | 平面设计 | 多 媒 体 | 程序开发 | 硬件资料 | 聊天软件
您现在的位置: 先创网 >> 程序开发 >> .NET >> 文章正文
用Asp.net实现基于XML的留言簿之三
itbulo.com
2005-7-19文/Asp.net
    


(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:#FFFFCC" >
< 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 >

打印此页 投稿与建议 返回顶部
栏 目 索 引
软件应用 SOFTWARE
Win XP | NT/2003
Win2000 | DOS/Win9x
PowerPoint | Office
Excel | Word
网络软件 | 实用软件
媒体软件 | 系统软件
常用软件 | 办公软件
聊天软件 | 网络安全
新软试用 | Vista
设计在线 DESIGN
Dreamweaver | 3DMax
Photoshop | Flash
平面设计 | 网页设计
多 媒 体 | 精品画廊
精彩专区 SPECIAL
Q Q 专区 | 热门专题
组网玩网 | 程序开发
应用集锦 |

没有任何图片文章
相关文章
关于我们 - 联系方式 - 合作伙伴 - 网站大事记 - 网站地图 - 我要投稿
Copyright ©1997-2008 先创网 All Rights Reserved.
先创科技 版权所有