Link to home
Start Free TrialLog in
Avatar of Howard Katz
Howard KatzFlag for United States of America

asked on

Format currency in ItemTemplate

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
Avatar of Anil Golamari
Anil Golamari
Flag of United States of America image

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)
<%# Format((Convert.ToDouble(Eval("Quantity")) *  Convert.ToDouble(Eval("UnitCost"))),"c")%>
Avatar of saritapatel
saritapatel

'<%#Format(Convert.ToDouble(Eval("netQty")*Eval("UnitCost")),"c") %>'
Avatar of Howard Katz

ASKER

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>
ASKER CERTIFIED SOLUTION
Avatar of Howard Katz
Howard Katz
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
What else should I do.