?
Solved

Null Date in Databinder.Eval(Container.DataItem, "decom")

Posted on 2006-05-28
4
Medium Priority
?
3,809 Views
Last Modified: 2010-04-26
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
0
Comment
Question by:donaldcroswell
  • 3
4 Comments
 
LVL 12

Expert Comment

by:TheMegaLoser
ID: 16782235
Change the function header to:

Function doMyDateCheck(ByVal myDate Object)

Then you can examine it for NULL values, do formatting or whatever you like.
0
 
LVL 12

Expert Comment

by:TheMegaLoser
ID: 16782260
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
0
 
LVL 12

Accepted Solution

by:
TheMegaLoser earned 2000 total points
ID: 16782261
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
0
 

Author Comment

by:donaldcroswell
ID: 16782275
GRRRREAT!
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
The Relationships Diagram is a good way to get an overall view of what a database is keeping track of. It is also where relationships are defined. A relationship specifies how two tables connect to each other. As you build tables in Microsoft Ac…
Watch the video to learn how one can deal with PST file corruption issue with an outstanding Kernel for Outlook PST Repair Tool easily. Using this tool, non-technical users can swiftly perform the repair process to restore their essential data witho…
Suggested Courses
Course of the Month3 days, 11 hours left to enroll

599 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question