我有一个手动编程的网格视图。我拥有所有事件的所有方法,一切似乎都在工作,但 RowUpdating 事件。我收到此错误:“对象引用未设置为对象的实例。” 我无法弄清楚这里发生了什么。所有控件都输入了值。这是我的代码。我究竟做错了什么??
protected void Gridview1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "update t_sizer_calibration " +
"set " +
"date = @date " +
" time = @time, " +
"name = @name, " +
"lane = @lane, " +
"carriers = @carrier, " +
"rev = @REV, " +
"new_tare = @n_tare, " +
"current_tare = @ctare, " +
"min = @min, " +
"max = @max," +
"sd = @sd, " +
"wai = @wai, " +
"bad_carriers = @badcar, " +
"comments = @comments " +
"where calibration_id = @calibration_id";
// define parameters
cmd.Parameters.Add("@calibration_id", SqlDbType.VarChar).Value = glblID.Text;
cmd.Parameters.Add("@date", SqlDbType.VarChar).Value = gtxtDate.Text;
cmd.Parameters.Add("@time", SqlDbType.VarChar).Value = gtxtTime.Text;
cmd.Parameters.Add("@name", SqlDbType.Int).Value = glblName.Text;
cmd.Parameters.Add("@lane", SqlDbType.Int).Value = Convert.ToInt32(gtxtLane.Text);
cmd.Parameters.Add("@carrier", SqlDbType.Decimal).Value = Convert.ToDecimal(gtxtCarriers.Text);
cmd.Parameters.Add("@REV", SqlDbType.Decimal).Value = Convert.ToDecimal(gtxtREV.Text);
cmd.Parameters.Add("@n_tare", SqlDbType.Decimal).Value = Convert.ToDecimal(gtxtN_Tare.Text);
cmd.Parameters.Add("@ctare", SqlDbType.Decimal).Value = Convert.ToDecimal(gtxtC_Tare.Text);
cmd.Parameters.Add("@min", SqlDbType.Decimal).Value = Convert.ToDecimal(gtxtMin.Text);
cmd.Parameters.Add("@max", SqlDbType.Decimal).Value = Convert.ToDecimal(gtxtMax.Text);
cmd.Parameters.Add("@sd", SqlDbType.Decimal).Value = Convert.ToDecimal(gtxtSD.Text);
cmd.Parameters.Add("@wai", SqlDbType.Decimal).Value = Convert.ToDecimal(gtxtWAI.Text);
cmd.Parameters.Add("@badcar", SqlDbType.Int).Value = Convert.ToInt32(gtxtBadCarriers.Text);
cmd.Parameters.Add("@comments", SqlDbType.VarChar).Value = gtxtComments.Text;
cmd.CommandType = CommandType.Text;
cmd.Connection = this.sqlConnection1;
this.sqlConnection1.Open();
//execute insert statement
cmd.ExecuteNonQuery();
this.sqlConnection1.Close();
//re-populate grid
fill_grid();
GridView1.EditIndex = -1;
GridView1.DataBind();
}
这也是我的 rowupdated 方法:
protected void GridView1_RowUpdated(object sender, GridViewUpdatedEventArgs e)
{
fill_grid();
//Reset the edit index.
GridView1.EditIndex = -1;
//Bind data to the GridView control.
GridView1.DataBind();
}