469,927 Members | 1,983 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,927 developers. It's quick & easy.

DataFormatString in GridView does not work??

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
Dec 12 '05 #1
1 6124
OK, I found solution, I must set HtmlEncode="false" to enable formatting.
"Hardy Wang" <ha*******@hotmail.com> wrote in message
news:eq*************@TK2MSFTNGP10.phx.gbl...
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

Dec 12 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by frank | last post: by
reply views Thread by Henry Lee | last post: by
1 post views Thread by needin4mation | last post: by
2 posts views Thread by Beemer Biker | last post: by
6 posts views Thread by Steve Harclerode | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.