Ajax+gridview+xml's Simple message book

Source: Internet
Author: User
Tags object eval tostring
Ajax|xml

aspx file
<%@ Page language= "C #" autoeventwireup= "true" codefile= "Default.aspx.cs" inherits= "_default"%>




Untitled Page






















User name: <% #Eval ("name")%> message time: <% #Eval ("Sdate")%>
message content: <% #Eval ("Couent")%>


















<TR><TD style= "width:306px" > Name<TR><TD style= "WIDTH:306PX; HEIGHT:77PX "> Message content<TR><TD colspan= "2" > < /tr>






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)
{
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



xiaoxiao
xiaoxoao
2006-11-14 21:06:14


Download code here Http://www.cnblogs.com/Files/TeaGreen/liuyanbo.rar



Related Article

Alibaba Cloud 10 Year Anniversary

With You, We are Shaping a Digital World, 2009-2019

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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.