• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 760
  • Last Modified:

format varchar to currency in datalist

Hi,

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:

<ItemTemplate>
                              <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>
                              </tr>
                        </ItemTemplate>

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.
0
savache27
Asked:
savache27
1 Solution
 
Bob LearnedCommented:
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").

Bob
0
 
DhaestCommented:
Perhaps you can perform the layout in the sql-script.
Something like this: CONVERT(varchar, CONVERT(money, YourFieldName), 1)
0
 
DotNetThinkerCommented:
try this...

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

That worked :) Thanks for the help!
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now