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

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.