Rahul Soni's blog

Never assume the obvious is true!

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

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

  • Comments 8

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 http://lab.msdn.microsoft.com/productfeedback/viewfeedback.aspx?feedbackid=b00b3ec6-e8fa-4f4d-b1e9-39162abc847b. 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 http://blogs.msdn.com/rahulso/archive/2006/02/28/540839.aspx. Try commenting out the line which says, bndColumn.HtmlEncode = False and see the effect.

To know more about BoundField.DataFormatString Property visit http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.boundfield.dataformatstring.aspx

Hope that helps!

  • Thank you!!! I've been searching for an answer to this issue for a while now.
  • Thank You!
  • Awesome - could not find the cure.  Thanks!!!!
  • Thank you very much!
  • <html>
  • HtmlEncode="false" set this property of the particular column for which you want to add dataformatstring..

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

  • 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...


Page 1 of 1 (8 items)
Leave a Comment
  • Please add 2 and 7 and type the answer here:
  • Post