Thursday, October 12, 2006

Beware of HtmlEncode in GridView DataBound fields

I tried to use asp:BoundField DataFormatString="{0:d}" in asp:GridView for displaying date in short format.
Unfortunately it didn't work - I still was getting long date format, completely disregarding DataFormatString property value.

After some googling I found out that HtmlEncode needs to be set to false, in order to allow DataFormatString property work.

Read this
MSDN HtmlEncode note:
"When the HtmlEncode property is true, the value of the field is HTML encoded to its string representation before the formatting string is applied. For some objects, such as dates, you might want to control how the object is displayed with a formatting string. In those cases, you must set the HtmlEncode property to false."

Technologies: ASP.NET 2.0 ASP.NET 2005 C# VB.NET GridView control DataBound field.

No comments:

Followers

About Me

My photo
Email me: blog@postjobfree.com