項目中的

 使用gridview控件實現操作問題。首先從數據庫中高出數據使其顯示在gridview上。。
string str = ConfigurationManager.ConnectionStrings["cnnstring"].ConnectionString;
using (SqlConnection sqlcnn = new SqlConnection(str))
{
using (SqlCommand sqlcmm = sqlcnn.CreateCommand())
{
sqlcmm.CommandText = "select * from gonggao";
SqlDataAdapter da = new SqlDataAdapter(sqlcmm);
DataSet ds = new DataSet();
da.Fill(ds);
this.GridView1.DataSource = ds.Tables[0];
this.GridView1.DataBind();
}
}
然後進行對它的增加與其增加
protected void Button1_Click(object sender, EventArgs e)
{
int i = 0;
string str = ConfigurationManager.ConnectionStrings["cnnstring"].ConnectionString;
using (SqlConnection sqlcnn = new SqlConnection(str))
{
using (SqlCommand sqlcmm = sqlcnn.CreateCommand())
{
sqlcmm.CommandText = "insert into gonggao values(@themes,@name,@date)";
sqlcmm.Parameters.AddWithValue("@themes", this.txtthemes.Text);
sqlcmm.Parameters.AddWithValue("@name", this.txtname.Text);
sqlcmm.Parameters.AddWithValue("@date", this.txtdate.Text);
sqlcnn.Open();
i= sqlcmm.ExecuteNonQuery();
}
}
if (i == 1)
{
ClientScript.RegisterStartupScript(GetType(),"t","<javascript>alert('ok')</javascript>");
}
else
Response.Write("<script>alert('插?入¨?失º¡ì敗㨹!ê?');</script>");
}
protected void Button2_Click(object sender, EventArgs e)
{
Response.Redirect("企¨®業°¦Ì公?告?.aspx");
}
查詢:
string search_name = this.txtchakan.Text;
int leixing = Convert.ToInt32(this.DropDownList1.SelectedValue);

string sql = "select * from gonggao where themes like '%" + search_name + "%'";
DataTable dt = sqlhelp.ExecuteTable(sql);
this.GridView1.DataSource = dt;
this.GridView1.DataBind();
使用超鏈接的方法,點擊所需項目的內空在另一個頁面顯示出來用到了datanavigateurlfields與datanavigateurlformatstring

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章