format varchar to currency in datalist

Posted on 2007-08-06
Last Modified: 2013-11-05

I am trying to format a varchar (using MS SQL Server) to display as a currency in a datalist in VS. This is my code and phone_amount is what needs to be displayed as a currency:

                              <tr bgcolor="WhiteSmoke">
                                    <TD align="left"><FONT face="Verdana" size="1"><%#container.dataitem("phone_year")%></FONT></TD>
                                    <TD align="left"><FONT face="Verdana" size="1"><%#container.dataitem("phone_month")%></FONT></TD>
                                    <TD align="left"><FONT face="Verdana" size="1"><%#container.dataitem("Employee")%></FONT></TD>
                                    <TD align="left"><FONT size="1" face="Verdana"><%#container.dataitem("PhoneNumber")%></FONT></TD>
                                    <td align="left"><FONT face="Verdana" size="1"><%#container.dataitem("FunctionalAccount")%></FONT></td>
                                    <td align="left"><FONT face="Verdana" size="1"><%#container.dataitem("phone_amount")%></FONT></td>
                                    <td align="left"><FONT face="Verdana" size="1"><%#container.dataitem("web_verified")%><%#container.dataitem("web_who")%></FONT></td>
                                    <td align="left"><FONT face="Verdana" size="1">[<a href='AlltelVerify.aspx?id=<%#container.dataitem("id")%>&s=1'>Verify</a>]&nbsp;&nbsp;&nbsp;[<a href='AlltelRemove.aspx?id=<%#container.dataitem("id")%>&s=1'>Remove</a>]&nbsp;&nbsp;&nbsp;[<a href='Amount.aspx?id=<%#container.dataitem("id")%>&s=1'>Amount</a>]</FONT></td>

I think I need to format as a double, but I'm not sure how to do that. If you could help me I would really appreciate it.
Question by:savache27
    LVL 96

    Expert Comment

    by:Bob Learned
    If you data is numeric, then you can use ToString("c").  If it is string, then you need to convert to double, and then use ToString("c").

    LVL 53

    Expert Comment

    Perhaps you can perform the layout in the sql-script.
    Something like this: CONVERT(varchar, CONVERT(money, YourFieldName), 1)
    LVL 12

    Accepted Solution

    try this...

    <%# String.Format("{0:c}", container.dataitem("phone_amount").ToString()) %>

    Author Comment


    That worked :) Thanks for the help!

    Featured Post

    Threat Intelligence Starter Resources

    Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

    Join & Write a Comment

    Suggested Solutions

    Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
    International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
    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…
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

    745 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

    21 Experts available now in Live!

    Get 1:1 Help Now