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

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
 
C

Craig Deelsnyder

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.
 
G

Guest

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
 
C

Craig Deelsnyder

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top