Solved

How to display amount values with just a decimal point, comma seperators and a leading hyphen for negative values but with no dollar sign in a GridView in ASP.NET?

Posted on 2013-12-04
2
830 Views
Last Modified: 2013-12-08
I am developing my first ASP.NET application in C# using VS2010.

I placed a (Data) GridView control on a Web Form.

For one of the fields titled AMT, this field that has an amount value and I just
want it to display the "Decimal point" and "Comma separator" as the DataFormatString.
How would I display the field in the GridView with just a decimal point and (thousands) comma separator. I don't want the dollar sign. And for negative amounts,  I want to precedie the amount with a dash.

For ex:

-80,000.00
        33.12
0
Comment
Question by:zimmer9
2 Comments
 
LVL 27

Accepted Solution

by:
Chinmay Patel earned 500 total points
Comment Utility
 int result = -80000;
 string value = result.ToString("N2");

Open in new window


Source: http://stackoverflow.com/questions/1048643/format-a-double-value-like-currency-but-without-the-currency-sign-c
0
 

Author Comment

by:zimmer9
Comment Utility
After dragging the GridView control from the Data section of the Tool Box onto my web form, I am trying to put a value into the "DataFormatString" field ofthe Smart Tag of the GridView control to convert a number into proper formatting.

The formatting I want is to put a dash in front of a negative number
and place a decimal point and (thousands) comma separator into a numeric value.

Thus, if the GridView row field is pulling from a database a value of 64786, the amount would be displayed in the GridView as 64,786.00

And if the GridView row field pulls in from a database a value of -221, it would appear in the GridView as -221.00.

The GridView field amount field is stored in default.aspx as follows:

If the GridView control cannot handle this editing "AMOUNT" field, then can the following ASPX CODE be modified to handle the reformatting of the AMOUNT field?

<asp:BoundField DataField="amount" HeaderText="Amount" SortExpression="amount" />
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now