Click here to Skip to main content
15,889,931 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have an asp:repeater that has a problem when trying to display a NULL DATE value from an SQL database.
HTML
<%# Databinder.Eval(Container.DataItem, "myDate") %>
Any suggestions on how to display the info in a repeater if it is a dateTime OR if it is a NULL date?
Posted
Updated 10-Dec-13 11:07am
v3
Comments
bowlturner 10-Dec-13 17:25pm    
Is this just to display? if so you can format the dates to string and the null can be an empty string.
creepz03 10-Dec-13 18:57pm    
I agree with this guy.. if it's only for display then convert in to string.

Hi Priya

Try like this to display "NULL" if it is a null value


HTML
Text='<%# Eval( "myDate") == DBNull.Value ? "NULL" : Eval( "myDate") %>' 
 
Share this answer
 
HTML
SelectedDate='<%#checkNullValues(DataBinder.Eval(Container.DataItem, "RefundDate"))%>'

C#
protected DateTime checkNullValues(object refundDate)
    {
        DateTime voidDate = Convert.ToDateTime("1/1/1900");
        if (refundDate == null || refundDate=="" || refundDate==DBNull.Value)
          return VoidDate;

        else
            return Convert.ToDateTime(refundDate);
    }
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900