Format user entered value in Grid cell

Posted on 2009-04-30
Medium Priority
Last Modified: 2012-05-06
I am using DataGridView. User can enter values in  the cells. My question is how  I can format entered values.
Let say user entered 50 and I want to display it  as $50.00.

Thank you
Question by:crcsupport

Assisted Solution

ppittle earned 400 total points
ID: 24274069
You can use the DataFormatString property of the BoundField to indicate how to display the data:

<asp:BoundField DataField="UnitPrice" DataFormatString="{0:c}"
            HtmlEncode="False" SortExpression="UnitPrice" />

Using the value "{0:c}" will format the value into currency.

This MSDN article explains more options that can be used to further customize data formating:

Accepted Solution

crcsupport earned 0 total points
ID: 24274886
the grid is not data bound. I came up with code that allows me to do so. Thank you for your response

Featured Post

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

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

Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
High user turnover can cause old/redundant user data to consume valuable space. UserResourceCleanup was developed to address this by automatically deleting user folders when the user account is deleted.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…

809 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