次の方法で共有


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 https://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 https://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 https://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.boundfield.dataformatstring.aspx

Hope that helps!

Comments

  • Anonymous
    March 12, 2006
    Thank you!!! I've been searching for an answer to this issue for a while now.

  • Anonymous
    April 21, 2006
    Thank You!

  • Anonymous
    May 11, 2006
    Awesome - could not find the cure.  Thanks!!!!

  • Anonymous
    May 30, 2006
    Thank you very much!

  • Anonymous
    August 24, 2006
    <html>
    <body>Anand</body></html>

  • Anonymous
    February 28, 2007
    HtmlEncode="false" set this property of the particular column for which you want to add dataformatstring..

  • Anonymous
    May 18, 2007
    Thank you so much. By the way how did you find it?

  • Anonymous
    May 18, 2007
    The comment has been removed