Solved

Format currency in ItemTemplate

Posted on 2011-02-24
6
709 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
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

 

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

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

Normally the drop down box control found in the .Net framework tools is able to select just one data and value at a time, which is displayed on the text area.   But what if you want to have multiple values to be selected in the drop down box? As …
This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

744 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

12 Experts available now in Live!

Get 1:1 Help Now