Link to home
Start Free TrialLog in
Avatar of donaldcroswell
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.Eval(Container.DataItem, "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
Avatar of TheMegaLoser
TheMegaLoser
Flag of Sweden image

Change the function header to:

Function doMyDateCheck(ByVal myDate Object)

Then you can examine it for NULL values, do formatting or whatever you like.
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
ASKER CERTIFIED SOLUTION
Avatar of TheMegaLoser
TheMegaLoser
Flag of Sweden image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of donaldcroswell
donaldcroswell

ASKER

GRRRREAT!