I’m trying in RowDataBound event to get a value from dataTable for the current editing row:
Here’s my code:
string KK = (string)DataBinder.Eval(e.Row.DataItem, "Name");
if ( KK == "John" )
{
//execute code
}
ERROR : Unable to cast object of type ‘System.DBNull’ to type ‘System.String’. at the first line ( the one with String KK…)
How can I fix that?
Use
DataItemof theGridViewRowinstead ofDataBinder.Evalto get the underlying datasource:The
Fieldextension method also supports nullable types.