donaldcroswell
asked on
Null Date in Databinder.Eval(Container.DataItem, "decom")
Hello All
I have an asp:repeater that has a problem when trying to display a NULL DATE value from an SQL database.
<%# Databinder.Eval(Container. DataItem, "myDate") %>
If I put in a function to check for a NULL value first, it still doesn't like the type being passed in (DBNull.Value or System.DateTime) I'm stuck with one or the other.
<%# doMyDateCheck(Databinder.E val(Contai ner.DataIt em, "myDate")) %>
Function doMyDateCheck(ByVal myDate As System.DateTime)
'I get an error when I pass in the code as DBNull or DateTime depending on which I declare and which gets passed in.(opposites generate error)
End Function
Any suggestions on how to display the info in a repeater if it is a dateTime OR if it is a NULL date?
Many thanks
Don Croswell
I have an asp:repeater that has a problem when trying to display a NULL DATE value from an SQL database.
<%# Databinder.Eval(Container.
If I put in a function to check for a NULL value first, it still doesn't like the type being passed in (DBNull.Value or System.DateTime) I'm stuck with one or the other.
<%# doMyDateCheck(Databinder.E
Function doMyDateCheck(ByVal myDate As System.DateTime)
'I get an error when I pass in the code as DBNull or DateTime depending on which I declare and which gets passed in.(opposites generate error)
End Function
Any suggestions on how to display the info in a repeater if it is a dateTime OR if it is a NULL date?
Many thanks
Don Croswell
For example:
Function doMyDateCheck(ByVal myDate As Object)
Dim sResult As DateTime
Try
sResult = DirectCast(myDate, DateTime)
Return sResult.ToShortDateString
Catch
Return "No date entered"
End Try
End Function
Function doMyDateCheck(ByVal myDate As Object)
Dim sResult As DateTime
Try
sResult = DirectCast(myDate, DateTime)
Return sResult.ToShortDateString
Catch
Return "No date entered"
End Try
End Function
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
GRRRREAT!
Function doMyDateCheck(ByVal myDate Object)
Then you can examine it for NULL values, do formatting or whatever you like.