Use Asp.net to implement XML-based message Book 3

Source: Internet
Author: User

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


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.