Solved

Gridview and "NULL" DateTime

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

617 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