Question : Null Date in Databinder.Eval(Container.<wbr />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

Answer : Null Date in Databinder.Eval(Container.<wbr />DataItem, "decom")

Even better:


    Function doMyDateCheck(ByVal myDate As Object) As String
        Dim sResult As DateTime
        Try
            sResult = DirectCast(myDate, DateTime)
            Return sResult.ToShortDateString
        Catch
            Return "No date entered"
        End Try
    End Function
Random Solutions  
 
programming4us programming4us