Datagrid datetime: empty datatime column shows "1/1/0001", how to avoid this?

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

  1. Hello

    I tried this issue a few days ago and no luck, so I am trying again. Basically I have a column in my datagrid that can be empty, null, at times. It works fine when it has actual date but if not shows 1/1/0001 instead of a nothing

    The only solution so far was to change the type to string, but then again the sorting doesn't work propertly

    So any idea how to deal with the column staying as datetime, and showing nothing when the value from db is null

    btw. I am treating the case when the data from database is nul

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

  2. Re: Datagrid datetime: empty datatime column shows "1/1/0001", howto avoid this?

    Reza wrote:

    > Hello,
    >
    > I tried this issue a few days ago and no luck, so I am trying again. Basically I have a column in my datagrid that can be empty, null, at times. It works fine when it has actual date but if not shows 1/1/0001 instead of a nothing.
    >
    > The only solution so far was to change the type to string, but then again the sorting doesn't work propertly!
    >
    > So any idea how to deal with the column staying as datetime, and showing nothing when the value from db is null?
    >
    > btw. I am treating the case when the data from database is null
    >
    > Thanks in advance,
    > Reza


    Add a handler for the ItemDataBound event. In that event, you can
    access the cell's data value (e.Item.DataItem), check if it's null or
    empty, and display an empty string if necessary. See if you can do this
    and not mess up your sorting.

    --
    Craig Deelsnyder
    Microsoft MVP - ASP/ASP.NET
    Craig Deelsnyder, Mar 2, 2004
    #2
    1. Advertising

  3. Craig

    Thanks for the response
    It resolved the issue of showing wrong information, but when it comes to paging or sorting it freezes

    ----- Craig Deelsnyder wrote: ----

    Reza wrote

    > Hello
    >> I tried this issue a few days ago and no luck, so I am trying again. Basically I have a column in my datagrid that can be empty, null, at times. It works fine when it has actual date but if not shows 1/1/0001 instead of a nothing
    >> The only solution so far was to change the type to string, but then again the sorting doesn't work propertly
    >> So any idea how to deal with the column staying as datetime, and showing nothing when the value from db is null
    >> btw. I am treating the case when the data from database is nul
    >> Thanks in advance

    > Rez


    Add a handler for the ItemDataBound event. In that event, you can
    access the cell's data value (e.Item.DataItem), check if it's null or
    empty, and display an empty string if necessary. See if you can do this
    and not mess up your sorting

    --
    Craig Deelsnyde
    Microsoft MVP - ASP/ASP.NE
    =?Utf-8?B?UmV6YQ==?=, Mar 2, 2004
    #3
  4. Re: Datagrid datetime: empty datatime column shows "1/1/0001", howto avoid this?

    Reza wrote:

    > Craig,
    >
    > Thanks for the response.
    > It resolved the issue of showing wrong information, but when it comes to paging or sorting it freezes!
    >
    > ----- Craig Deelsnyder wrote: -----
    >
    > Reza wrote:
    >
    > > Hello,
    > >> I tried this issue a few days ago and no luck, so I am trying again. Basically I have a column in my datagrid that can be empty, null, at times. It works fine when it has actual date but if not shows 1/1/0001 instead of a nothing.
    > >> The only solution so far was to change the type to string, but then again the sorting doesn't work propertly!
    > >> So any idea how to deal with the column staying as datetime, and showing nothing when the value from db is null?
    > >> btw. I am treating the case when the data from database is null
    > >> Thanks in advance,

    > > Reza

    >
    > Add a handler for the ItemDataBound event. In that event, you can
    > access the cell's data value (e.Item.DataItem), check if it's null or
    > empty, and display an empty string if necessary. See if you can do this
    > and not mess up your sorting.
    >
    > --
    > Craig Deelsnyder
    > Microsoft MVP - ASP/ASP.NET
    >


    Interesting....perhaps you should make the text itself invisible then.
    Make the column a TemplateColumn, with a Label that displays the date
    for each row. In your handler, make the Label in that e.Item invisible
    if the datasource value is null. Then of course you might have to be
    careful on the way back (if you're updating the datasource later on) to
    check for these values and send null instead.

    --
    Craig Deelsnyder
    Microsoft MVP - ASP/ASP.NET
    Craig Deelsnyder, Mar 2, 2004
    #4
    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:
    1
    Views:
    2,933
    Raterus
    Feb 27, 2004
  2. Tan
    Replies:
    1
    Views:
    703
    =?Utf-8?B?Q293Ym95IChHcmVnb3J5IEEuIEJlYW1lcikgLSBN
    Oct 17, 2005
  3. Tan
    Replies:
    6
    Views:
    7,325
    Juan T. Llibre
    Oct 20, 2005
  4. Christos TZOTZIOY Georgiou
    Replies:
    3
    Views:
    691
    Christos TZOTZIOY Georgiou
    Sep 13, 2003
  5. Tim Peters
    Replies:
    0
    Views:
    524
    Tim Peters
    Sep 9, 2003
Loading...

Share This Page