Results 1 to 4 of 4

Thread: Formatting currency using Databinder.Eval method

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2002
    Location
    Toronto, Ontario
    Posts
    12

    Formatting currency using Databinder.Eval method

    Hi all

    I'm trying to format a currency as well as a date using code that I found in MSDN. The actual MSDN page:

    http://msdn.microsoft.com/library/de...sevaltopic.asp


    The actual code on my ASP.NET page:

    <td class="DataCell" style="width=100px"><nobr><%# DataBinder.Eval(Container.DataItem, "unit_cost", "{0:c}") %></nobr></td>

    It's exactly the same line, but the data still outputs on the page as an unformatted currency. I've tried uppercase "C" and lowercase "c", but it just seems to ignore the format parameter. Am I doing something wrong here?

    Any help appreciated. P.S. Can anyone tell me what I have to wrap around my text to make the code appear as "code"?
    Thanks.

  2. #2
    Fanatic Member aconybeare's Avatar
    Join Date
    Oct 2001
    Location
    UK
    Posts
    772

    Re: Formatting currency using Databinder.Eval method

    I've not had a chance to test you problem out, but thought should help out with your second question.

    You place either of the following tags around your code (note: I've used backslash before each square bracket to prevent the tags from rendering.
    \[code\] your code goes here \[/code\]
    \[vbcode\]your code goes here\[/vbcode\]


    if you use IE then this is an excellent tool showthread

    If you use the main post new thread page there is a toolbar one of the options is vbCode just hilight your code then click the toolbar item and it will insert the tags

  3. #3
    C# Aficionado Lord_Rat's Avatar
    Join Date
    Sep 2001
    Location
    Cave
    Posts
    2,497

    Re: Formatting currency using Databinder.Eval method

    For the sake of clarity, the above examples would be used exactly like:

    [code]YOUR CODE[/code]

    or

    [vbcode]YOUR CODE[/Highlight]
    Need to re-register ASP.NET?
    C:\WINNT\Microsoft.NET\Framework\v#VERSIONNUMBER#\aspnet_regiis -i

    (Edit #VERSIONNUMBER# as needed - do a DIR if you don't know)

  4. #4
    New Member leparduk's Avatar
    Join Date
    Oct 2005
    Posts
    7

    Re: Formatting currency using Databinder.Eval method

    try one of the following

    Code:
    <ASP:BOUNDCOLUMN datafield="UnitPrice" sortexpression="UnitPrice" headertext="UnitPrice" dataformatstring="{0:c}"></ASP:BOUNDCOLUMN>
    OR

    Code:
    					<ASP:TEMPLATECOLUMN headertext="UnitPrice">
    						<ITEMTEMPLATE>
    							<asp:Label runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.UnitPrice", "{0:c}") %>'>
    							</ASP:LABEL>
    						</ITEMTEMPLATE>
    					</ASP:TEMPLATECOLUMN>
    Hope this helps
    Just because you're paranoid doesn't mean they aren't out to get you

    Quidquid latine dictum sit, altum viditur

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width