gridview 编辑更新代码更新不了值是怎么回事/

来源:百度知道 编辑:UC知道 时间:2024/06/08 01:53:33
点击更新时候,textbox值不变
protected void gvCategoryList_RowUpdating(object sender, GridViewUpdateEventArgs e)
{

int ID = Convert.ToInt32(gvCategoryList.DataKeys[e.RowIndex].Value.ToString());
GridViewRow myrow = gvCategoryList.Rows[e.RowIndex];
string _Name = ((TextBox)(gvCategoryList.Rows[e.RowIndex].Cells[1].Controls[0])).Text.ToString();
string _Number = ((TextBox)(gvCategoryList.Rows[e.RowIndex].Cells[2].Controls[0])).Text.ToString();

ad.ExecuteSqlWrite("Update qq set Name='" + _Name + "',Number='" + _Number+ "' where QQID=" + ID);
gvCategoryList.EditIndex = -1;
databind();
}

http://hi.baidu.com/hixmuhot/blog/item/437d99f17e19dba6a40f52f1.html
希望对你有帮助

SqlConnection con = DBClass.Getcon();
try
{
con.Open();
string sql = "update Item set title='"+((TextBox)(GridView1.Rows[e.RowIndex].Cells[1].Controls[0])).Text.Trim()+"'where Itemid='"+GridView1.DataKeys[e.RowIndex].Value.ToString()+"' ";
SqlCommand cmd = new SqlCommand(sql,con);
cmd.ExecuteNonQuery();
this.GridView1.EditIndex = -1;
bind();
}
catch (Exception ex)
{
this.Response.Write(ex.Message);

}
finally
{
con.Close();
}