?? viewguestbook.aspx
字號:
<%--
viewguestbook.aspx
這個文件是用于查看留言簿的內容的,該例展示了如何打開、讀、寫一個XML文件。
使用 Repeater 去顯示留言簿包含的內容
--%>
<%@ Page Language="C#" %>
<%@ Import Namespace="System" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Data" %>
<%-- 所需要的集合 --%>
<html>
<head>
<title>第四十四例 基于XML的留言簿 </title>
<script language="C#" runat=server>
//當頁面被裝載時執行該腳本
public void Page_Load(Object sender, EventArgs e)
{
//該路徑下的 Xml 文件包含了所有的數據
string datafile = "db/guest.xml" ;
//使用try-Catch 模塊讀 XML 文件
try
{
//生成一個DataSet 對象
DataSet guestData = new DataSet();
//為操作數據庫,打開一個 FileStream
FileStream fin ;
fin = new FileStream(Server.MapPath(datafile),FileMode.Open, FileAccess.Read,FileShare.ReadWrite) ;
//讀出數據庫的內容到 DataSet 中
guestData.ReadXml(fin);
fin.Close();
//數據綁定到表格
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>
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -