(2) viewguestbook. aspx:
<% @ Page Language = "C #" %>
<% @ Import Namespace = "System" %>
<% @ Import Namespace = "System. IO" %>
<% @ Import Namespace = "System. Data" %>
<% -- The above is the required namespace -- %>
<Html>
<Head>
<Title> welcome to my guestbook </title>
<Script language = "C #" runat = server>
// Run the script after the page is downloaded.
Public void Page_Load (Object sender, EventArgs e)
{
// Path of the XML file containing all data
// If your path is different from the following, modify
String datafile = "db/guest. xml ";
// Use a Try-Catch Block to read information
Try
{
// Create a DataSet object
DataSet guestData = new DataSet ();
// Open a FileStream for the database file
FileStream fin;
Fin = new FileStream (Server. MapPath (datafile), FileMode. Open,
FileAccess. Read, FileShare. ReadWrite );
// Read data from the database
GuestData. ReadXml (fin );
Fin. Close ();
// Pay the dataset in the first table to Repeater
MyDataList. DataSource = guestData. Tables [0]. DefaultView;
MyDataList. DataBind ();
}
Catch (Exception edd)
{
// Catch exceptions
Errmess. Text = "cannot read data from XML files. Cause:" + 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 message book <ASP: Repeater id = "MyDataList" runat = "server">
<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>
Message
</Th>
<Th>
Date/time
</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>