我得到NULLREFERENCEEXCEPTION
在gridview更新查詢。爲什麼我在下面的代碼中獲得NULL EXCEPTION?
protected void GridView1_RowUpdating(Object sender, GridViewUpdateEventArgs e)
{
TextBox txtname = (TextBox)GridView1.Rows[e.RowIndex].FindControl("txtname1");
cmd.Connection = con;
cmd.CommandText = "update test1 set Name='" + txtname.Text + "' where Roll_No = '"
+ GridView1.DataKeys[e.RowIndex].Values[0].ToString() + "'";
con.Open();
int temp = cmd.ExecuteNonQuery();
if (temp == 1)
{
Label1.Text = "Record updated sucessfully";
}
GridView1.EditIndex = -1;
FillGrid();
con.Close();
}
請使用調試器來確定哪個東西是空的。代碼中有很多可能性,我們無法猜測。 – Mat 2013-04-20 09:35:30
什麼樣的調試器? – 2013-04-20 09:38:18
把你的gridview結構放在這裏。 – 2013-04-20 09:39:29