Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1749
  • Last Modified:

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>
0
gianitoo
Asked:
gianitoo
1 Solution
 
David RobitailleAnalyst ProgrammerCommented:
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

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

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now