DataFormatString not working in GridView

  • Thread starter Thread starter Alan Silver
  • Start date Start date
A

Alan Silver

Hello,

I have a GridView control, and am unsuccessfully trying to format a
column to show costs. The (simplified) code is as follows...

<asp:GridView ID="grdCustomers" DataSourceID="dtaCustomers"
AutoGenerateColumns="false" runat="server">
<Columns>
<asp:BoundField DataField="Total" DataFormatString="&pound;{0:F2}" />
</Columns>
</asp:GridView>

As you can see, I have set the DataFormatString to "&pound;{0:F2}",
which should give them a Pound sign, followed by the value with two
decimal places (like you would expect a cost to look).

The problem is that the numbers are not being formatted correctly. I
have things like $23.9 (where I have changed the pound sign to a dollar
sign to ensure it shows up right in Usenet). This should show as $23.90,
with the extra zero.

Any ideas? TIA
 
try DataFormatString = &pound; {0:0.00}, but what you have should
work...

Thanks for the suggestion, but that didn't work either.

It worries me when you say what I have should work!! Is there anything
else I can check to see why it isn't. Thanks again
 
What is the datatype of "Total" (.NET data type or Database data type)

It's a computed field that comes from an SQL expression like...

select sum(priceeach*quantity) from siteorders...

where "priceeach" is a float and "quantity" is an int.

Thanks
 
Back
Top