gridview的更新和取消的问题。网上有人问我说数据在update后还保持编辑的状态。怎么改变起状态。

 void BindData()
    {
        string sql = "select top 10 ID,jobno,jobfixno,jobtype from jobse";
        SqlDataAdapter myda = new SqlDataAdapter(sql, conn);
        DataSet ds = new DataSet();
        myda.Fill(ds, "RusTable");
        GridView1.DataSource = ds.Tables["RusTable"].DefaultView;
        GridView1.DataBind();
        conn.Close();
    }
    protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
    {
        GridView1.EditIndex = e.NewEditIndex;
    }

    protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
    {
        GridView1.EditIndex = -1;
        BindData();
    }
    protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        TextBox tb = (TextBox)GridView1.Rows[e.RowIndex].FindControl("TextBox001");
        string dkvalue = GridView1.DataKeys[e.RowIndex].Value.ToString();
        string sql1 = "update jobse set jobno='" + tb.Text.ToString() + "' where id='" + dkvalue + "'";
        conn.Open();
        SqlCommand cmd = new SqlCommand(sql1, conn);
        cmd.ExecuteNonQuery();
        conn.Close();
        GridView1.EditIndex = -1;
        BindData();
    }

你可能感兴趣的:(gridview的更新和取消的问题。网上有人问我说数据在update后还保持编辑的状态。怎么改变起状态。)