Custom software developer. IT consultant. Geek.
Applying a FormatString to a column in a GridView
I ran across a very frustrating problem today when working on a project for a client. I was placing a GridView onto a page, into which went a number of fields, one of which is a dollar amount. I did a quick search and discovered that the BoundColumn has a property called DataFormatString. Sounds good, I say. So into this field I put the old familiar “{0:c}”, only to discover that my grid was still showing numbers like “1.0000″ or “0.9900″. After a lot of head scratching, some MSDN reading, and a lot of Googling, I finally found the answer…
For the DataFormatString to be applied in a BoundColumn of a GridView, the HtmlEncode property must be set to False.
I don’t think I understand WHY this is the case, but it’s comforting to know that it’s a definite solution to the problem.
|
Follow comments to this post through RSS 2.0. Both comments and pings are currently closed. |
Comments are closed.