Solved

Format currency in ItemTemplate

Posted on 2011-02-24
6
714 Views
Last Modified: 2012-05-11
Hi,
How would I get this to appear as currency.

<%# (Convert.ToDouble(Eval("Quantity")) *  Convert.ToDouble(Eval("UnitCost")))%>

this is in an asp.net 4.0 application
Thanks
0
Comment
Question by:katzhoward
6 Comments
 
LVL 18

Expert Comment

by:Anil Golamari
ID: 34972819
http://lawrence.ecorp.net/inet/samples/regexp-validate2.php ( Javascript function)

http://www.regexlib.com/DisplayPatterns.aspx (Regular Expression to validate)

decimal moneyvalue = your value;
string html = String.Format("Order Total: {0:C}", moneyvalue);
Console.WriteLine(html);

(C# String format code)
0
 
LVL 9

Expert Comment

by:mayank_joshi
ID: 34978262
<%# Format((Convert.ToDouble(Eval("Quantity")) *  Convert.ToDouble(Eval("UnitCost"))),"c")%>
0
 
LVL 2

Expert Comment

by:saritapatel
ID: 35004581
'<%#Format(Convert.ToDouble(Eval("netQty")*Eval("UnitCost")),"c") %>'
0
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 

Author Comment

by:katzhoward
ID: 35007809
Thanks to both of you but neither suggestion has an effect.  Here is the code that surrounds this line.  It is in a gridview.

<Columns>
<asp:BoundField DataField="ProductID" HeaderText="Product ID"  ....
<asp:BoundField DataField="ModelNumber" HeaderText="Model Number" ....
<asp:BoundField DataField="ModelName" HeaderText="Model Name" ....
<asp:BoundField DataField="UnitCost" HeaderText="Unit Cost" DataFormatString="{0:c}" />        
<asp:TemplateField>
    <HeaderTemplate>Quantity</HeaderTemplate>
    <ItemTemplate>
      <asp:TextBox  runat="server" Text='<%# Bind("Quantity") %>' />
    </ItemTemplate>
</asp:TemplateField>    
       
<asp:TemplateField>
    <HeaderTemplate>Item&nbsp;Total</HeaderTemplate>
    <ItemTemplate>
       <%# (Convert.ToDouble(Eval("Quantity")) *  Convert.ToDouble(Eval("UnitCost")))%>
    </ItemTemplate>

</asp:TemplateField>                
<asp:TemplateField>
    <HeaderTemplate>Remove&nbsp;Item</HeaderTemplate>
    <ItemTemplate>
          <center>
            <asp:CheckBox id="Remove" runat="server" />
          </center>
    </ItemTemplate>
</asp:TemplateField>
</Columns>
0
 

Accepted Solution

by:
katzhoward earned 0 total points
ID: 35021308
I found the answer.  

<%# (Convert.ToDouble(Eval("Quantity")) * Convert.ToDouble(Eval("UnitCost"))).ToString("C2")%>  
0
 

Author Closing Comment

by:katzhoward
ID: 37089838
What else should I do.
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

The object model of .Net can be overwhelming at times – so overwhelming that quite trivial tasks often take hours of research. In this case, the task at hand was to populate the datagrid from SQL Server database in Visual Studio 2008 Windows applica…
Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

777 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