aspx file
<%@ Page language= "C #" autoeventwireup= "true" codefile= "Default.aspx.cs" inherits= "_default"%>
<! DOCTYPE HTML PUBLIC "-//w3c//dtd XHTML 1.1//en" "Http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd" >
<title> Untitled Page </title>
<body>
<form id= "Form1" runat= "Server" >
<div>
<asp:scriptmanager id= "ScriptManager1" runat= "Server" >
</asp:ScriptManager>
</div>
<asp:updatepanel id= "UpdatePanel1" runat= "Server" >
<ContentTemplate>
<asp:gridview id= "GridView1" runat= "server" cellpadding= "0" forecolor= "#333333" gridlines= "None" allowpaging= " True "autogeneratecolumns= False" width= "100%" onpageindexchanging= "gridview1_pageindexchanging" PageSize= "5" Borderstyle= "Solid" borderwidth= "1px" >
<Columns>
<asp:TemplateField>
<ItemTemplate>
<table border= "0" cellpadding= "2" cellspacing= "1" >
<tr>
<td> User name: <% #Eval ("name")%> message time: <% #Eval ("Sdate")%></td>
</tr>
<tr><td><tr><td> message content: <% #Eval ("Couent")%></td></tr>
</table>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<pagerstyle horizontalalign= "right"/>
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>
<asp:updatepanel id= "UpdatePanel2" runat= "Server" >
<ContentTemplate>
<table>
<TR><TD style= "width:306px" > Name
<asp:textbox id= "TextBox1" runat= "Server" width= "144px" ></asp:TextBox></td></tr>
<TR><TD style= "WIDTH:306PX; HEIGHT:77PX "> Message content
<asp:textbox id= "TextBox2" runat= "Server" textmode= "MultiLine" width= "223px" height= "109px" ></asp:textbox ></td></tr>
<TR><TD colspan= "2" > <asp:button id= "Button1" runat= "Server" onclick= "Button1_Click" text= "Submit" skinid= "O"/></td></tr>
</table>
</ContentTemplate>
</asp:UpdatePanel>
</form>
</body>
CS file
Using System;
Using System.Data;
Using System.Configuration;
Using System.Web;
Using System.Web.Security;
Using System.Web.UI;
Using System.Web.UI.WebControls;
Using System.Web.UI.WebControls.WebParts;
Using System.Web.UI.HtmlControls;
Public partial class _default:system.web.ui.page
{
protected void Page_Load (object sender, EventArgs e)
{ Br>if (! Page.IsPostBack)
{
Binddata ();
}
}
private void Binddata ()
{
DataSet ds = new DataSet ();
Ds. READXML (Server.MapPath ("XMLFile.xml"));
Gridview1.datasource = ds;
Gridview1.databind ();
}
protected void Button1_Click (object sender, EventArgs e)
{
DataSet ds = new DataSet ("my");
Ds. READXML (Server.MapPath ("XMLFile.xml"));//Read XML file
DataRow dr = ds. Tables[0]. NewRow ();
dr["name"] = TextBox1.Text.ToString ();
dr["couent"] = TextBox2.Text.ToString ();
dr["sdate"] = DateTime.Now;
DS. Tables[0]. Rows.Add (DR);
DS. WriteXml (Server.MapPath ("XMLFile.xml"));//write XML file
Response.Redirect ("default.aspx");
}
protected void Gridview1_pageindexchanging (object sender, Gridviewpageeventargs e)
{
Gridview1.pageindex = E.newpageindex;
Binddata ();
}
}
XML file
<?xml version= "1.0" standalone= "yes"?>
<person>
<user>
<name>xiaoxiao</name>
<couent>xiaoxoao</couent>
<sdate>2006-11-14 21:06:14</sdate>
</user>
</person>
Download code here Http://www.cnblogs.com/Files/TeaGreen/liuyanbo.rar