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
917 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
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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

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

Suggested Solutions

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

685 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