DataFormatString in GridView does not work??

H

Hardy Wang

Hi, I have a GridView control in my web form (ASP.NET 2.0)

<asp:GridView ID="gvReport" runat="server" AllowSorting="True"
AutoGenerateColumns="False"
Width="100%">
<HeaderStyle CssClass="ItemCaption" />
<RowStyle CssClass="Line" />
<AlternatingRowStyle CssClass="AltLine" />
<Columns>
<asp:BoundField DataField="ItemName" HeaderText="Item
Name" SortExpression="ItemName" />
<asp:BoundField DataField="PurchaseDate"
DataFormatString="{0:F}" HeaderText="Purchase Date"
SortExpression="PurchaseDate" />
<asp:BoundField DataField="Cost"
DataFormatString="{0:c}" HeaderText="Cost"
SortExpression="Cost" />
<asp:BoundField DataField="UnitPrice"
DataFormatString="{0:c}" HeaderText="Unit Price"
SortExpression="UnitPrice" />
<asp:BoundField DataField="Quantity"
HeaderText="Quantity" SortExpression="Quantity" />
</Columns>
</asp:GridView>

I want to format the output of "Cost" and "UnitPrice" columns to display in
currency format, thus I added DataFormatString="{0:c}" to column
declaration. Does it suppose to show the result of these two columns like
"$1,000.00", "$0.99"? But actually what I can get is all "1000.0000",
"0.9900"!
I created a dummy function in this web page to run string s =
cost.ToString("C"); the output is currect.
Anything wrong with GridView?


Regards
Hardy
 

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

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top