Format user entered value in Grid cell

Posted on 2009-04-30
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
    LVL 8

    Assisted Solution

    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:
    LVL 1

    Accepted Solution

    the grid is not data bound. I came up with code that allows me to do so. Thank you for your response

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    As more and more people are shifting to the latest .Net frameworks, the windows presentation framework is gaining importance by the day. Many people are now turning to WPF controls to provide a rich user experience. I have been using WPF controls fo…
    This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
    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.…
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…

    737 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

    20 Experts available now in Live!

    Get 1:1 Help Now