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
Solved

Gridview and "NULL" DateTime

Posted on 2006-07-21
1
1,573 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
1 Comment
 
LVL 24

Accepted Solution

by:
Justin_W earned 500 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

809 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