Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Gridview and "NULL" DateTime

Posted on 2006-07-21
1
Medium Priority
?
1,625 Views
Last Modified: 2010-08-05
I have a Gridview with an ObjectDataSource bound to it. The class handling the SelectMethod returns some DateTime fields that are for all purposes NULL, but actually DateTime.MinValue since a DateTime cannot be NULL.

I don't want to display these values in the Gridview, since they don't make any sense. Is it bad form to type a method as Object and return different types like so:

        public object Fax
        {
            get
            {
                if (fax.Date == DateTime.MinValue)
                {
                    return null;
                }
                else
                {
                    return fax;
                }
            }
            set { fax = (DateTime)value; }
        }

If it is, how could I inform the Gridview to hide the DateTime.MinValue?
0
Comment
Question by:DarinAlred
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 24

Accepted Solution

by:
Justin_W earned 2000 total points
ID: 17157140
> Is it bad form to type a method as Object and return different types like so:

It is absolutely not bad practice. It does seem kind of inelegant from a purist's POV, but unfortunately that is one of the best solutions that we as developers are left with given Microsoft's implementation of DBNull/null/valuetype issues.
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

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…
Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

688 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