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.
V

Salman BegRank #284 · 8.8K reputationPosted Apr 15, 2021, 1:34 PM EDT
Sachin SinghRank #66 · 26.2K reputationPosted Apr 15, 2021, 1:36 PM EDT
Valerie MeunierRank #1,527 · 1K reputationPosted Apr 15, 2021, 5:23 PM EDT
Valerie MeunierRank #1,527 · 1K reputationPosted Apr 15, 2021, 5:49 PM EDT
Valerie MeunierRank #1,527 · 1K reputationPosted Apr 16, 2021, 4:18 AM EDT