Valerie Meunier

Valerie Meunier

  • NA
  • 693
  • 82.9k

problem with empty field in gridview when updating

Apr 15 2021 4:48 PM
Hi
 
When editing a row of a gridview, some fields can remain empty.
But with this code, i get the error (if field 'name" remained empty) when updating: "Object reference not set to an instance of an object.":
protected void GridView1_RowUpdating(object sender, System.Web.UI.WebControls.GridViewUpdateEventArgs e)
string name;
name = e.NewValues["name"].ToString();
I tried to prevent that with this code:
if (string.IsNullOrEmpty(e.NewValues["name"].ToString()) == true)
name = e.NewValues["name"].ToString();
else
name ="";
But I get the same error (at line if ...)
 
Thanks for help.
 

Answers (5)