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

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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
 
Reza said:
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

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
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
 
Reza said:
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: -----


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.

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.
 
Back
Top