Datagrid, empty date: How show nothing for date value - now shows 1/1/0001??

Discussion in 'ASP .Net' started by =?Utf-8?B?UmV6YQ==?=, Feb 27, 2004.

  1. Hi

    I have a column in my datagrid that can have values of null at times. I am not assigning any value to it, if it is coming from Database empty. Now, the problem is I guess the datetime variables have a default value. Thus shows an undesirable value of 1/1/0001

    How do I go about not showing anything when the value is null like this

    Thanks in advance
    Reza
     
    =?Utf-8?B?UmV6YQ==?=, Feb 27, 2004
    #1
    1. Advertising

  2. =?Utf-8?B?UmV6YQ==?=

    Raterus Guest

    are you sure they are nulls or just empty data fields. (In my experience
    "nulls" crash things if you haven't specifically coded around them) Either
    way, you should be able to define a function that you can put in your
    databinding syntax <%# %> or in your itemdatabound event that will give you
    the date you want. Your function would be something like this.

    Private Function getDate(ByVal myDate As Object) As String
    getDate = CStr(myDate)

    If getDate = "1/1/0001" Then
    getDate = String.Empty
    End If

    Return getDate
    End Function

    then in your datagrid, define a templatecolumn for this column
    <asp:templatecolumn headertext="Date">
    <itemtemplate>
    <%# getDate(DataBinder.Eval(Container.DataItem, "myDate")) %>
    </itemtemplate>
    </asp:templatecolumn>

    hope this helps
    --Michael

    "Reza" <> wrote in message
    news:...
    > Hi,
    >
    > I have a column in my datagrid that can have values of null at times. I am

    not assigning any value to it, if it is coming from Database empty. Now, the
    problem is I guess the datetime variables have a default value. Thus shows
    an undesirable value of 1/1/0001.
    >
    > How do I go about not showing anything when the value is null like this?
    >
    > Thanks in advance,
    > Reza
     
    Raterus, Feb 27, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?UmV6YQ==?=
    Replies:
    3
    Views:
    5,528
    Craig Deelsnyder
    Mar 2, 2004
  2. Johannes Hammersen

    RangeValidator Minimum Date can not be 01.01.0001

    Johannes Hammersen, Nov 22, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    5,237
    Johannes Hammersen
    Nov 23, 2004
  3. gce
    Replies:
    0
    Views:
    772
  4. Tan
    Replies:
    1
    Views:
    719
    =?Utf-8?B?Q293Ym95IChHcmVnb3J5IEEuIEJlYW1lcikgLSBN
    Oct 17, 2005
  5. Tan
    Replies:
    6
    Views:
    7,366
    Juan T. Llibre
    Oct 20, 2005
Loading...

Share This Page