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
940 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

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

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

738 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