初学Ajax不久,自己写个小东西,以作学习日记
留言板图片如下:

样例地址:http://www.8dao.net/miniguest/
首先,这里用的是Access数据库,便于移动。
数据库很简单,表Guest,字段有ID,Name,Content
要实现Ajax,利用asp.net ajax 1.0 bate是很方便的,在http://ajax.asp.net可以下载到。
安装好后打开VS2005,新建一个ASP.net AJAX Enabled Web Site项目
在里面添加一个WEB用户控件 MiniGB.ascx,控件代码如下:
<%@ Control Language="C#" ClassName="MiniGB" %>
<%@ Import Namespace="System.Data.OleDb" %>
<%@ Import Namespace="System.Data" %>
<script runat="server">
private OleDbConnection conn = new OleDbConnection("provider=microsoft.jet.oledb.4.0;data source="+System.Web.HttpContext.Current.Server.MapPath("guest.mdb"));
private string dname = "游客";
public string Dname
{
get
{
return dname;
}
set
{
dname = value;
}
}
protected void Button1_Click(object sender, EventArgs e)
{
if (TextBox1.Text.Trim() != "")
{
OleDbCommand comm = new OleDbCommand("insert into guest(name,content)values(''"+dname+"'',''" + TextBox1.Text.Trim() + "'')", conn);
comm.ExecuteNonQuery();
listupdate();
TextBox1.Text = "";
}
}
private void listupdate()
{
OleDbDataAdapter da = new OleDbDataAdapter("select top 5 * from guest order by id desc", conn);
DataSet ds = new DataSet();
da.Fill(ds);
DataList1.DataSource = ds;
DataList1.DataBind();
}
protected void Page_Load(object sender, EventArgs e)
{
conn.Open();
listupdate();
}
</script>
<style>
.Gtitle
{
width:200px;
background-color:#464646;
color:#FFFFFF;
font-size:14px;
height:20px;
padding: 3px 0 0 10px;
font-weight:bold;
border-style:solid;
border-top-width:1px;
border-bottom-width:0px;
border-left-widt
