mercredi 9 décembre 2015

if condition not behaving the way I expect

I have a gridview with a boundfield that contains DateTime columns. In the OnRowDataBound event I check if that date is NOT NULL and depending on the result I do some action.

if (!String.IsNullOrEmpty(e.Row.Cells[16].ToString()))

BUT, even though the cell is NULL - would it be empty the date would be displayed as 1.1.1900 - the condition is always fulfilled!

I did some workaround replacing the null values with '' (empty) and therefore changed the condition into

if (!e.Row.Cells[16].Text != "01/01/1900 0:00:00")

This works, but then I have all this irrelevant data displayed in the gridview.

What's wrong?

Aucun commentaire:

Enregistrer un commentaire