Link to home
Start Free TrialLog in
Avatar of gianitoo
gianitoo

asked on

negative currency in gridview

My positive amounts are displaying like this    $75.00
My negative amounts are displaying like this    ($75.00)

I need my positive to stay the same and my negative to  display   -$75.00

                          <asp:BoundField DataField="unit_price1" DataFormatString="{0:c}"
                    HeaderText="Price" HtmlEncode="False" SortExpression="unit_price1"
                    ItemStyle-HorizontalAlign="center" ControlStyle-CssClass="titleboldprice" ItemStyle-CssClass="titleboldprice">
                    <ItemStyle HorizontalAlign="Center" />
                </asp:BoundField>
Avatar of David Robitaille
David Robitaille
Flag of Canada image

it s a format and "culture" question
DataFormatString="{0:c}"
is where your problem is

http://msdn.microsoft.com/en-us/library/0c899ak8.aspx
 
 
 

; 
 Section separator 
 The ';' character is used to separate sections for positive, negative, and zero numbers in the format string. If there are two sections in the custom format string, the leftmost section defines the formatting of positive and zero numbers, while the rightmost section defines the formatting of negative numbers. If there are three sections, the leftmost section defines the formatting of positive numbers, the middle section defines the formatting of negative numbers, and the rightmost section defines the formatting of zero numbers. 
 
The following example uses the format specifier for the section separator to format positive, negative, and zero numbers differently. 
 
Visual Basic Copy Code 
Dim posValue As Double = 1234
Dim negValue As Double = -1234
Dim fmt As String = "##;(##)"
Console.WriteLine(posValue.ToString(fmt))    ' Displays 1234
Console.WriteLine(negValue.ToString(fmt))    ' Displays (1234)
 
 
 

Open in new window

Avatar of gianitoo
gianitoo

ASKER

So how do i apply that in my gridview??  gridview below
field for price is  unit_price1

<asp:GridView ID="GridView4" runat="server" AutoGenerateColumns="False"
                                        DataKeyNames="rowpointer" DataSourceID="SqlDataSource4"  GridLines="None"
                                        EmptyDataText="No Options"
                                        OnRowDataBound="GridView4_RowDataBound"  ShowHeader="False">
                                        <RowStyle BackColor="White" ForeColor="#003399" />
                                        <Columns>
                                       
                                            <asp:BoundField DataField="itemdescription" HeaderText="Items"
                                               HtmlEncode="True"/>
                                                     <asp:BoundField DataField="unit_price1" DataFormatString="{0:c}"
                    HeaderText="Price" HtmlEncode="False" SortExpression="unit_price1"
                    ItemStyle-HorizontalAlign="center" ControlStyle-CssClass="titleboldprice" ItemStyle-CssClass="titleboldprice">
                    <ItemStyle HorizontalAlign="Center" />
                </asp:BoundField>
                                                <asp:TemplateField><ItemTemplate>
                                                 <asp:HyperLink ID="deleteme" runat="server" >Remove</asp:HyperLink>
                                                </ItemTemplate></asp:TemplateField>
                                            <asp:TemplateField HeaderText="Price">
                                           
                                                <FooterTemplate>
                                                    <asp:Label ID="lblSummary" Runat="server" />
                                                </FooterTemplate>
                                         
                                            </asp:TemplateField>
                                        </Columns>
                                       
                                    </asp:GridView>
ASKER CERTIFIED SOLUTION
Avatar of prairiedog
prairiedog
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial