ASP/DataGrid/BoundColumn/Data formatting expression fo Date?

  • Thread starter Thread starter Volodymyr Lozovoy
  • Start date Start date
I think so :)
but where?

Data format expression is {0:d}- short date format "05/06/04" (it is wrote
in help "Properties for Bound Columns"), but date is rendered as May 6 2004.
 
If you look in the help for BoundColumn.DataFormatString, you will find that
D (or d) displays numeric values in decimal format. It shouldn't affect date
fields, which is what you are observing.

You can format dates in code-behind in either ItemDataBound or PreRender
event. Get the cell text, convert it to DateTime and format it back to
string with format expression of your choice.

Eliyahu
 
I am newbie in .NET. May be i am wrong.
I agree with you about numeric value, but i have date value.
In the help for Standard DateTime Format Strings "d" is short date pattern.
 
Thank you! I found my mistake.

Eliyahu Goldin said:
If you look in the help for BoundColumn.DataFormatString, you will find
that
D (or d) displays numeric values in decimal format. It shouldn't affect
date
fields, which is what you are observing.

You can format dates in code-behind in either ItemDataBound or PreRender
event. Get the cell text, convert it to DateTime and format it back to
string with format expression of your choice.

Eliyahu
 

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

Back
Top