WEB开发网:viewpost.aspx--察看提交的留言 viewguestbook.aspx--察看所有留言 Header.inc guestpost.aspx--留言表单及XML写操作 Footer.inc
赞助商链接
中资源
>> 最新文章
>> 赞助商
>> 热门文章
WEB开发网文章阅读

一个ASP.NET+XML留言本例子

作者:未知 文章来源:WEB开发者 更新时间:2007-12-15 9:40:27
viewpost.aspx--察看提交的留言
viewguestbook.aspx--察看所有留言
Header.inc
guestpost.aspx--留言表单及xml(标准化越来越近了)写操作
Footer.inc
Guest.xml(标准化越来越近了)--xml(标准化越来越近了)数据

源代码如下:

viewguestbook.aspx
<%@ 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 //run the script when the Page is Loaded
public void Page_Load(Object sender, EventArgs e)
{
// an label , its use stated later
tryagain :

//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 xml(标准化越来越近了)DataDocument class
//this class can read from an xml(标准化越来越近了) file in and ordered format
xml(标准化越来越近了)DataDocument datadoc = new xml(标准化越来越近了)DataDocument();

// Infer the DataSet schema from the xml(标准化越来越近了) data and load the xml(标准化越来越近了) Data
datadoc.DataSet.Readxml(标准化越来越近了)(new StreamReader(Server.MapPath(datafile)));

//Databind the first table in the Dataset to the Repeter
MyDataList.DataSource = datadoc.DataSet.Tables[0].DefaultView;
MyDataList.DataBind();

//free up the xml(标准化越来越近了) file to be used by other programs
datadoc=null;


}
catch(IOException ed)
{
// Here I am for now trying to overcome a bug in my guestbook exapmle
//the Bug is that only one class can either read or write to my xml(标准化越来越近了)
// data file at a time.
//If the file is being used my some some other page (eg the guest book viewing page)
// then an IOException will be thrown
// So to handle such situtations what we do is that
// If an IOException is thrown the page goes again to the tryagain label
//and tries to write again into the xml(标准化越来越近了) file
//this goes on till finally the resource is freed and the xml(标准化越来越近了) file is written to.

goto tryagain ;
}
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">
<!-- <asp:label id="errmess" text="" style="color:<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: <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: <td>
<% </td>
<td>
<% </td>
<td>
<% </td>

[1] [2] [3] [4] [5]  下一页

百度搜索中共有相关主题
[阅读:次] [返回上一页] [打 印]
  • 相关文章
  • 本类热门