Problems with DataFormatString not workin in 2.0 controls?
It didn’t take long for me to run into this once I started playing with controls in 2005. In 2.0, if you want the following field to be displayed in currency, you would change it from this:
<asp:BoundField DataField=”Price” HeaderText=”Price” SortExpression=”Price” />
to this:
<asp:BoundField DataField=”Price” DataFormatString=”{0:c}” HeaderText=”Price” SortExpression=”Price” />
BUT, once you do this, you will find that yoru DataFormatString command had no effect whatsoever on your displayed values. To get this to work correctly, you have to also include “HtmlEncode=’false’” in your control definition. The finished product looks like this:
<asp:BoundField DataField=”Price” HtmlEncode=”false” DataFormatString=”{0:c}” HeaderText=”Price” SortExpression=”Price” />
Recent Comments