Format DataItem 'inline' as Currency/String?

Discussion in 'ASP .Net' started by D. Shane Fowlkes, Jun 9, 2005.

  1. I have a DataItem in a Template that calls a Function to perform a
    calculation. The Function returns a decimal value. Easy enough. It looks
    like this:

    <code>
    <%# CalculateExpended(Container.DataItem("StaffID")) %>
    </code>

    So how exactly can I format this to come out as currency? I can NOT format
    the output in the function. The function must return a decimal. I've tried
    something like the code below but that returns a "'System.Decimal' does not
    contain a property with the name {0:C}. " error.

    <code>
    <%# DataBinder.Eval(CalculateExpended(Container.DataItem("StaffID")),
    "{0:C}") %>
    </code>

    Thanks

    Just to emphasize - I cannot perform the formatting within the function! I
    must do this at the Template's DataItem level in the page. Thanks again...
    D. Shane Fowlkes, Jun 9, 2005
    #1
    1. Advertising

  2. Haven't tried, but how about:

    string.format("{0:c}", CalculateExpended(Container.DataItem("StaffID")))

    or, while I sense you can't format the data in the function:), how about a
    separate function, e.g. CalculateExpendedAsCurrency(container.dataitem,
    etc.), where in the code-behind it calls CalculateExpended?

    Bill

    "D. Shane Fowlkes" wrote:

    > I have a DataItem in a Template that calls a Function to perform a
    > calculation. The Function returns a decimal value. Easy enough. It looks
    > like this:
    >
    > <code>
    > <%# CalculateExpended(Container.DataItem("StaffID")) %>
    > </code>
    >
    > So how exactly can I format this to come out as currency? I can NOT format
    > the output in the function. The function must return a decimal. I've tried
    > something like the code below but that returns a "'System.Decimal' does not
    > contain a property with the name {0:C}. " error.
    >
    > <code>
    > <%# DataBinder.Eval(CalculateExpended(Container.DataItem("StaffID")),
    > "{0:C}") %>
    > </code>
    >
    > Thanks
    >
    > Just to emphasize - I cannot perform the formatting within the function! I
    > must do this at the Template's DataItem level in the page. Thanks again...
    >
    >
    >
    =?Utf-8?B?QmlsbCBCb3Jn?=, Jun 9, 2005
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Biao Tang
    Replies:
    0
    Views:
    459
    Biao Tang
    Apr 28, 2005
  2. TJS
    Replies:
    0
    Views:
    475
  3. D. Shane Fowlkes

    Format DataItem as Currency and NO decimals

    D. Shane Fowlkes, Mar 20, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    4,907
    Nathan Sokalski
    Mar 21, 2006
  4. adegreiff

    howto format currency string?

    adegreiff, Aug 29, 2003, in forum: Python
    Replies:
    3
    Views:
    544
    Alex Martelli
    Aug 29, 2003
  5. Joshua

    Format String to Currency

    Joshua, Sep 7, 2007, in forum: ASP .Net
    Replies:
    3
    Views:
    505
    Mark Rae [MVP]
    Sep 7, 2007
Loading...

Share This Page