DataFormatString not working in GridView

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
 
A

Alan Silver

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
 
A

Alan Silver

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top