BoundField and DataFormatString

  • Thread starter Thread starter yefei
  • Start date Start date
Y

yefei

I want to display a BoundField "Price" in the format of currency in a
GridView
I set the DataFormatString="{0:C}" in my program
However, it doesnot work.
I try to add a '$'in from of the brace, it shouw things like
"$2500.0000"
my data in the database is of 'decimal' with length=9
even i do this in the gridview, 'edit column' functionality, it is
still the same
but I can achieve this by converting the field to a template field
it is easy to do this if the 'Price' column is static
however, i need to add the 'Price" column dynamically by creating
BoundFields and add it according to some conditions.
So anybody knows the right ways to specify the DataFormatString?
Or it cannot apply to BoundField and i have to do it using
TemplateField, which is much more complicated?

need your help
 
On your GridView column, have you added the HtmlEncode="false"
attribute?

After the Beta 2, ASP.Net 2.0 treats all column values as strings and
won't format them with a numeric formatstring unless you add the above
attribute

<asp:BoundField DataField="Foo" DataFormatString="{0:c}"
HtmlEncode="False" />
 
Back
Top