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