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
<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