Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Datagrid datetime: empty datatime column shows "1/1/0001", how to avoid this?

Reply
Thread Tools

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

 
 
=?Utf-8?B?UmV6YQ==?=
Guest
Posts: n/a
 
      03-02-2004
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
 
Reply With Quote
 
 
 
 
Craig Deelsnyder
Guest
Posts: n/a
 
      03-02-2004
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
 
Reply With Quote
 
 
 
 
=?Utf-8?B?UmV6YQ==?=
Guest
Posts: n/a
 
      03-02-2004
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

 
Reply With Quote
 
Craig Deelsnyder
Guest
Posts: n/a
 
      03-02-2004
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
a question about c++ datatime could.net@gmail.com C++ 6 12-19-2006 12:51 PM
DataTime string format barry ASP .Net 4 02-14-2006 04:12 PM
DATATIME PATTERN based on regional optional settings Karunakararao ASP .Net 0 10-06-2004 03:52 PM
How to make a DataTime object from a string? Quentin Huo ASP .Net 3 09-15-2004 04:15 PM
Datagrid, empty date: How show nothing for date value - now shows 1/1/0001?? =?Utf-8?B?UmV6YQ==?= ASP .Net 1 02-27-2004 08:46 PM



Advertisments