NULL-Problem with Databinder.Eval using Replace
In my gridview I have a column where I want to display a tooltip from database. Using databinder.eval works pretty well as expected.
<%# DataBinder.Eval(Container.DataItem, "Skills" ) %>
Now I need to modify the result returned from the database because it contains commas as a seperator but I want to display the values with a line-break. As I could use ‘Replace’ this should not be a big problem:
<%# Replace(DataBinder.Eval(Container.DataItem, "Skills" ), ",", environment.newline) %>
Unfortunately this always throws an error because there is one line containing NULL:
Conversion from Type ‘DBNull’ to type ‘String’ is not valid.
But thanks to the internet I found a little trick posted by RuslanKhor:
You could add an empty string ( "" ) to the value to be replaced, and now everything works fine:
<%# Replace(DataBinder.Eval(Container.DataItem, "Skills" ) & "", ",", environment.newline) %>