Version: ASP.net 2.0 RTM
I wasted a few minutes figuring out this one.
You have a BoundField object bound to a field of type DateTime with a DataFormatString attribute but the format string is not being applied. <asp:BoundField DataField="DateOfBirth" DataFormatString="{0:MM/dd/yyyy}" />
Instead, the field appears to be formatted using its ToString()method like so:
Output: 10/31/2005 7:00:54 PM
Cause
To prevent cross site scripting attacks, the field value is HtmlEncoded. The HtmlEncoding occurs before applying the DataFormatString making the format string have no effect.
Resolution
In this case (ie. when using a field of type DateTime), set HtmlEncode to false.
<asp:BoundField DataField="DateOfBirth" DataFormatString="{0:MM/dd/yyyy}" HtmlEncode="false"/>
Output: 10/31/2005
I am not sure why the ASP.net team decided against HtmlEncoding the string after applying the DataFormatString.
3:26:35 PM
|