Solved

Gridview and "NULL" DateTime

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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

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…
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

747 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now