negative currency in gridview

gianitoo
gianitoo used Ask the Experts™
on
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>
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
David RobitailleAnalyst Programmer

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

Author

Commented:
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>
DataFormatString="{0:$ #,#.00}"

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial