navigation
 Saturday, September 16, 2006

If you have a BoundField in a GridView that displays a datetime, but you only want to display the date, how would you go about doing that?

Set the DataFormatString to "{0:d}" ?

That is what I thought too. Turns out, this doesn't always work.
That is because by default the value is extracted from the data store, HtmlEncoded, and then the format string is applied. After HtmlEncoding,  the format string won't do anything. The fix in most cases, is usually pretty simple. Just turn off HtmlEncoding for that field by setting HtmlEncode="false".
If you can't turn off HtmlEncoding, it looks like there is some custom formating in your future.