BLOG留言板代码 HTML

2025-01-04 07:36:17
推荐回答(2个)
回答1:

教你一个用reapter实现的,下面是reapter的click事件里的代码:
public void BindRepeater()
{
SqlConnection conn = new SqlConnection("Data Source=.;Initial Catalog=MyMvp;Integrated Security=True");
SqlDataAdapter da = new SqlDataAdapter("Select * from message", conn);
DataTable dt = new DataTable();
da.Fill(dt);
Repeater1.DataSource = dt;
Repeater1.DataBind();
}
//留言按钮:
protected void Button1_Click(object sender, EventArgs e)
{
if (Session["username"] == null)
{ Response.Redirect("Login.aspx"); }
else
{
SqlConnection conn = new SqlConnection("Data Source=.;Initial Catalog=MyMvp;Integrated Security=True");
string msgTime = DateTime.Now.ToString();
string titles = this.TextBox1.Text.ToString();
SqlCommand cmd = new SqlCommand("Insert into message(title,username,msgTime) values('" + titles + "','" + Session["username"].ToString() + "','" + msgTime + "')", conn);
conn.Open();
cmd.ExecuteNonQuery();
conn.Close();
BindRepeater();
}

回答2:

这全是留言板:自己挑个吧!
http://www.codefans.net/sort/list_2_34_1.shtml