?? tianjia.aspx.cs
字號:
?using System;
using System.Data;
using System.Configuration;
using System.Collections;
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;
using System.Data.SqlClient;
public partial class tianjia : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
this.DataBindToDataList();
}
}
protected void btntijiao_Click(object sender, EventArgs e)
{
string biaoti,time,content,id;
id = txtid.Text.Trim();
biaoti = txtbiaoti.Text.Trim();
content = txtneirong.Text.Trim();
time = DateTime.Now.ToString();
SqlConnection con = DB.CreateCon();
con.Open();
SqlCommand cmd = new SqlCommand("insert into news(newsid,newsbiaoti,newstime,newscontent) values ('" + id + "','" + biaoti + "','" + time + "','" + content + "')", con);
cmd.ExecuteReader();
this.DataBindToDataList();
Response.Write("<script language=javascript> window.alert('恭喜你,添加成功!')</script>");
}
private void DataBindToDataList()
{
SqlConnection con = DB.CreateCon();
SqlDataAdapter sda = new SqlDataAdapter();
sda.SelectCommand = new SqlCommand("select * from news", con);
DataSet ds = new DataSet();
sda.Fill(ds, "new");
this.DataList1.DataSource = ds.Tables["new"];
this.DataList1.DataBind();
}
protected void btnquxiao_Click(object sender, EventArgs e)
{
Response.Redirect("index.aspx");
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -