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!