Formatting a GridView date?

D

David Veeneman

How does one format a date column in a GridView control? I had assumed that
the DataFormat string would do it, but MSDN only shows numeric formatting
codes. Can dates be formatted using that property, or is it done some other
way?

Thanks in advance.
 
D

David Veeneman

I found my answer. The standard date formatting strings work just like the
numeric formatting strings shown in the documentation. The trick is to set
the column's HTMLEncode property to false. The date formatting string is
entered using the same syntax as a numeric formatting string. For example,
{0:d} will give a date a 'short date' format.
 
D

David Veeneman

One point of clarification for anyone else researching this issue: The
HTMLEncode property must be set to false whenever the DataFormatString
property is used, whether for date or numeric data.
 

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,994
Messages
2,570,223
Members
46,813
Latest member
lawrwtwinkle111

Latest Threads

Top