Solved

Gridview and "NULL" DateTime

Posted on 2006-07-21
1
1,578 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 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

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…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

734 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