Ok, so I have a repeater on my aspx page. One of the fields is a date. I want to format this to the shortdate format. The date comes from a database, so it could be null, which is what causes the problem. Here is my code...
I get an error...
"System.InvalidCastException: Cast from type 'DBNull' to type 'Date' is not valid"
I think I know WHY I get this error... its like the second Container.DataItem takes precendence over the iif. Not sure why... and I don't know how to fix it!
But if I simply do
then I get the results I expect. So, I know the check is working correctly.
Does anyone know how to fix this?
Thanks!
Thanks - Todd
Code:
<%# iif(not (DataBinder.Eval(Container.DataItem, "DueDate") is System.DBNull.Value), FormatDateTime(DataBinder.Eval(Container.DataItem, "DueDate"), DateFormat.ShortDate), "") %>
I get an error...
"System.InvalidCastException: Cast from type 'DBNull' to type 'Date' is not valid"
I think I know WHY I get this error... its like the second Container.DataItem takes precendence over the iif. Not sure why... and I don't know how to fix it!
But if I simply do
Code:
<%# iif(not (DataBinder.Eval(Container.DataItem, "DueDate") is System.DBNull.Value), "1", "2") %>
then I get the results I expect. So, I know the check is working correctly.
Does anyone know how to fix this?
Thanks!
Thanks - Todd