復制代碼 代碼如下:
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
sqlcon = new SqlConnection(strCon);
sqlcon.Open();
string bianhao = Convert.ToString(this.GridView1.DataKeys[e.RowIndex].Value);
string beizhu = ((TextBox)(GridView1.Rows[e.RowIndex].Cells[6].Controls[0])).Text.ToString();
string sqlstr = "SQL語句'";
sqlcom = new SqlCommand(sqlstr, sqlcon);
sqlcom.ExecuteNonQuery();
sqlcon.Close();
GridView1.EditIndex = -1;
bind();
}
取列的值為原來的,並不是更新後的,原因是因為Page_Load中加載了數據,每次更新後會自動刷新,所以需在Page_Load中判斷一下是否頁面回傳,再加載,如下
復制代碼 代碼如下:
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
bind();
}
}