I was coding with breeze rendering my tabular data with the use of a GridView control. I successfully bound it to my ObjectDataSource and the data were displaying just fine except for one minute problem. My DateTime column was rendered as “raw” format from my SQL Server. This means that my date column displays “8/12/2006 11:47 AM”.
Using my experience from DataGrid control from my ASP.Net 1.1 days, I immediately set the value of my DateTime column’s DataFormatString property to “{0:d}” (short datetime format). I saved the page and refreshed the browser finding my DateTime column still displaying the same “raw” format. What seems to be the problem?
After some time searching for solutions, I came across this article from Microsoft Connect site. It says that string formatting for DataFormatString works well with ASP.NET 2.0 up until their Beta 2 release.
Solution? Just set the HtmlEncode property of your BoundField from true (default) to false. MS explanation:
This is by design. Because HtmlEncode is on, the data is retrieved from the data store, HtmlEncoded, and then the format string is applied. By HtmlEncoding the value from the data store, we are protecting unsafe script from the data store from being displayed to the client.
Now we know
Thanks a lot!
You could also fix this on back end.
SELECT CONVERT(CHAR(10), yourdatecolumn, 101)
But there is no HTMLEncode property in .Net 1.1 . got any other ideas?
for .net 1.1, you can set the value of your DateTime column’s DataFormatString property to “{0:d}”