景甜跟谢霆锋综艺节目:DataGrid不能更新??急急急急急!!

来源:百度文库 编辑:高考问答 时间:2024/05/06 06:14:55
private void DataGrid1_UpdateCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{

string updatecmd="update jobs set job_desc=@jobdesc,min_lvl=@minlvl,max_lvl=@maxlvl where job_id=@jobid";
SqlCommand mysqlcom=new SqlCommand(updatecmd,con);
mysqlcom.Parameters.Add(new SqlParameter("@jobid",SqlDbType.SmallInt,2));
mysqlcom.Parameters.Add(new SqlParameter("@jobdesc",SqlDbType.VarChar,50));
mysqlcom.Parameters.Add(new SqlParameter("@minlvl",SqlDbType.TinyInt,1));
mysqlcom.Parameters.Add(new SqlParameter("@maxlvl",SqlDbType.TinyInt,1));
mysqlcom.Parameters["@jobid"].Value=((TextBox)e.Item.Cells[1].Controls[0]).Text;
mysqlcom.Parameters["@jobdesc"].Value=((TextBox)e.Item.Cells[2].Controls[0]).Text;
mysqlcom.Parameters["@minlvl"].Value=((TextBox)e.Item.Cells[3].Controls[0]).Text;
mysqlcom.Parameters["@maxlvl"].Value=((TextBox)e.Item.Cells[4].Controls[0]).Text;
mysqlcom.Connection.Open();
mysqlcom.ExecuteNonQuery();
mysqlcom.Connection.Close();
this.InitDataGrid();

就是在文本框中更改了文本,返回的还是原来的值,这是为啥呀

更新后要重新执行一下Binding(),且控件的isPostBack为ture才可以,再就是Controls[0]好像应该是FindControls