c# - How to convert null to string in Event Gridview RowDeleting on Textbox -


i want convert value null string in event gridview rowdeleting on textbox. but error "object reference not set instance of object."

code behide:

protected void gvterm_rowdeleting(object sender, gridviewdeleteeventargs e) { textbox txtcountryrate_te = (textbox)gvterm.rows[e.rowindex].findcontrol("txtcountryrate_te");                                     if (txtcountryrate_te == null)             {                 txtcountryrate_te.text = string.empty;  //<== error object reference not set instance of object.             }   } 

thanks in advance. ;)

the error tells happening. trying access , set property of null object.

to set string.empty text object. create new instance of object empty text.

    protected void gvterm_rowdeleting(object sender, gridviewdeleteeventargs e)     {         textbox txtcountryrate_te = (textbox)gvterm.rows[e.rowindex].findcontrol("txtcountryrate_te");         if (txtcountryrate_te == null)         {             txtcountryrate_te = new textbox             {                 text = string.empty             };         }     } 

how ever default value string.empty can simplify to

txtcountryrate_te = new textbox(); 

Comments

Popular posts from this blog

android - Gradle sync Error:Configuration with name 'default' not found -

java - Andrioid studio start fail: Fatal error initializing 'null' -

html - jQuery UI Sortable - Remove placeholder after item is dropped -