打印本文 打印本文  关闭窗口 关闭窗口
ASP.NET: XML留言版第二版
作者:采集员 文章来源:来源于网络 点击数: 更新时间:2005/9/10 12:36:13
="color:#FF0000" runat="server" />
<center>
<h2 class="newsbody"><b>Thank You , for posting in My GuestBook.</b></h2>
<table align=center width="60%" border="0" cellspacing="2" cellpadding="1" >
<tr class="titheading"><td colspan="2">The information You Posted!</td></tr>
<tr class="newsbody">
<td>Name :</td>
<td><asp:label id="NameLabel" text="" runat="server" /></td>
</tr>
<tr class="newsbody">
<td>Country :</td>
<td><asp:label id="CountryLabel" text="" runat="server" /></td>
</tr>
<tr class="newsbody">
<td>E-mail :</td>
<td><asp:label id="EmailLabel" text="" runat="server"/></td>
</tr>
<tr class="newsbody">
<td>Comments :</td>
<td><asp:label id="CommentsLabel" text="" runat="server" /></td>
</tr>
</table>
<br>
<h4 class="newsbody"><a href="viewguestbook.aspx">Click here </a> to view GuestBook.</h4>
<br>
</center>
<!-- #Include File="footer.inc" -->
</body>
</html>




2) viewguestbook.aspx : The Guestbook viewing page.

<%@ Import Namespace="System" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Data" %>
<%@ Assembly Name="System.Xml" %>
<%@ Import Namespace="System.Xml" %>
<%@ Page Language="C#" %>
<%-- Needed Assembiles --%>
<html>
<head>
<title>Welcome to Saurabh's GuestBook.</title>
<script language="C#" runat=server>
//run the script when the Page is Loaded
public void Page_Load(Object sender, EventArgs e)
{
//the path to the Xml file which will contain all the data
//modify this if you have any other file or directory mappings.
//modify this if you have been directed here from Step 2 of the ReadMe file.
string datafile = "db/guest.xml" ;
//try-Catch block to read from an XML file
try
{
//make an instance to the XMLDataDocument class
//this class can read from an xml file in and ordered format
XmlDataDocument datadoc = new XmlDataDocument();
//Open a FileStream to the Database
FileStream fin ;
fin = new FileStream(Server.MapPath(datafile),FileMode.Open,
FileAccess.Read,FileShare.ReadWrite) ;
// Infer the DataSet schema from the XML data and load the XML Data
datadoc.DataSet.ReadXml(new StreamReader(fin));
//Databind the first table in the Dataset to the Repeater
MyDataList.DataSource = datadoc.DataSet.Tables[0].DefaultView;
MyDataList.DataBind();

//free up the XML file to be used by other programs
datadoc=null;

}
catch (Exception edd)
{
//catch any other exceptions that occur
errmess.Text="Cannot read from XML file because "+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">My Guestbook.</h3>
<ASP:Repeater id="MyDataList" runat="server">
<template name="headertemplate">
<table class="mainheads" width="100%" style="font: 8pt verdana">
<tr style="background-color:#FF9966">
<th>
Name
</th>
<th>
Country
</th>
<th>
Email
</th>
<th>
Comments
</th>
<th>
Date/Time
</th>
</tr>
</template>
<template name="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>

</template>

<template name="footertemplate">

</table>

</template>

</ASP:Repeater>

<!-- #Include File="footer.inc" -->
</body>
</html>


Saurabh Nandu


上一页  [1] [2] 



打印本文 打印本文  关闭窗口 关闭窗口