Formatting bound ASP.NET types requires explicitly changing the HtmlEncode property

I ran into this one while migrating our Beta 2 code to VS RTM for an internal reporting site, but the behavior for ASP.NET 2.0 changed within betas and, in short, anytime you want to add a formatting string, like any of the numeric or date format strings in a bound field , you have to explicitly set the HTMLEncode property to "false".

Here's what your code should look like with the newly added property in bold.

<asp:BoundField DataField="Total" DataFormatString="{0:#,###}" HtmlEncode ="False" />

Before HtmlEncode property After HtmlEncode property
Total100000000 Total100,000,000

Why does ASP.NET need the explicit HtmlEncode property? From an internal thread, the short answer is that ASP.NET will by default assume the value is html encoded and then treat it like a string which rules out numeric/date formatting.