DataFormatString of GridView control is not working and the columns don’t get formatted

Recently, I found an issue with the Gridview control. I was adding some formatted columns and no matter how much I tried it wouldn’t show up as expected. Similar code seems to work fine in Datagrid of VS 2003. One of the columns which I had was supposed to use the following formatting “{0:#,###}” and it simply didn’t work.

After some investigation I found that it was a problem due to HTMLEncoding. For more explanation you have view All you need to do is to set the BoundColumn’s HtmlEncode property to False.

To see how I formatted the GridView dynamically, visit the following link Try commenting out the line which says, bndColumn.HtmlEncode = False and see the effect.

To know more about BoundField.DataFormatString Property visit

Hope that helps!

Comments (8)

  1. Brent says:

    Thank you!!! I’ve been searching for an answer to this issue for a while now.

  2. Eric says:

    Thank You!

  3. John says:

    Awesome – could not find the cure.  Thanks!!!!

  4. SonDH says:

    Thank you very much!

  5. csd says:



  6. sachin pawar says:

    HtmlEncode="false" set this property of the particular column for which you want to add dataformatstring..

  7. Sue says:

    Thank you so much. By the way how did you find it?

  8. No Problems Sue! Being a troubleshooter at MS enlightens you with a lot of tricks, I guess!

    Mainly, I started by commenting some lines which I suspected and pretty soon figured out the culprit. I wanted to file a bug, but found that it is already filed and documented here…