当前位置: 首页 > 图文教程 > 网络编程 > ASP.NET > 用Asp.net实现基于XML的留言簿之三

ASP.NET
如何使用vb6.0来实现中文实名搜索
C#实现Window管道技术
记录下一些关于测试工具NUNIT的链接资料,有兴趣的朋友也可以跳过去看看
编写与.NET属性窗口交互的RAD组件(自序)
asp.net 关于form认证的一般设置:
编写与.NET属性窗口交互的RAD组件(一)
ActiveX控件的打包发布[无证书发布](一)
Visual SourceSafe 6.0 的问题思考
VB报表输出的问题,恳请不吝赐教
证书和签名--试用微软提供的证书测试工具系列
[dotNET]如何利用ConfigurationSettings.AppSettings.GetValues读取配置文件中多个...
使用C#编写DES加密程序的framework
令你的网页速度大大提高
怎样得到一个系统盘的全名,不是字符,是全名,如:本地磁盘(C:)?
r在richtextbox中插入动画/控件
Code: Writing Text to a File (Visual Basic)
算法讨论:哲学家就餐问题
我们所要关注的是什么?
firebird 连接嵌入式版本
从Csharp走到VB.Net(一):MyClass保留字

ASP.NET 中的 用Asp.net实现基于XML的留言簿之三


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-11-03   浏览: 74 ::
收藏到网摘: n/a

(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 >