Go Premium for a chance to win a PS4. Enter to Win

x
?
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
Medium Priority
?
1,046 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 2000 total points
ID: 39696202
 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
ID: 39696430
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses

877 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