BoundField DataFormatString attribute not working

I was stuck with a problem a few weeks ago where my DataFormatString on a BoundField in a GridView was not being applied. I had a chance to look at the code again today and found this very helpful post by Raj Kaimal with the fix this morning. The short answer is that you need to set HtmlEncode=“false” in order for the DataFormatString to work. The HtmlEncoding by default is designed to defeat cross site scripting attacks, but unfortunately the way it is implemented results in DataFormatString being ignored.

If you liked this post, consider subscribing to email updates about my new posts, or sharing it on Hacker News.

Keyboard shortcuts

?
Show this help
Esc
Close this help or an open menu
n
Next (newer) post: Team Foundation Source Control Tips
p
Previous (older) post: LLBLGen v2 Released
Tab
Move between links and buttons (Shift+Tab to go back)