Currency formatting in DataList

Posted on 2008-11-12
Last Modified: 2013-11-26
I have a data bound field in a DataList.  Trying to format it to show currency ($300,000) using the following.
<span style="color: #0000cd">Price:&nbsp;
                                        <asp:Label ID="BusPriceLabel" runat="server" Font-Bold="True" Font-Size="Medium"
                                            Style="font-size: small; position: relative;" Text='<%# Eval("BusPrice", "${0:###,###}") %>' ForeColor="Black"></asp:Label></span></td>

Unfortunately this only produces "$300000".  What am I doing wrong?
Question by:PrimeNY
    LVL 7

    Expert Comment

    Eval("BusPrice", "${0:#,###}")

    Author Comment

    the bachelor - Thanks but I've tried that and other similar versions and nothing seems to be recognized.
    LVL 7

    Accepted Solution

    Odd, I tried it and it worked for me.
    I'm assuming your using SQL server... What is the data type of your BusPrice column as in the resulset that your passing to the datalist?
    Also make sure that you're not experiencing Caching issues with the Browser so when you make changes they are effectively taken into account.
    LVL 7

    Expert Comment

    As an altenative you could try:
    Text='<%# String.Format("{0:$#,###}",Eval("BusPrice"))

    Author Comment

    Got it.  Problem was with the data type in the table.  Had it as VarChar instead of Money.  Thanks for your help.

    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

    Join & Write a Comment

    Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
    Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
    This video discusses moving either the default database or any database to a new volume.

    734 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

    23 Experts available now in Live!

    Get 1:1 Help Now