Formatting output fron Helper Function in Template? Syntax?

Discussion in 'ASP .Net' started by D. Shane Fowlkes, May 19, 2005.

  1. Hey guys. I have a Repeater and a Template. One of the dataitems calls a
    helper function. The dataitem sends the record ID to the function and the
    function runs a complex query and returns a calculation which is a dollar
    amount. The ID is a "construction project" and the helper function goes and
    determines how much money has already been spent against the project by
    querying expenditure tables.

    The function works fine but how can I format the output to be currency? I
    also noticed that even though my function returns data of a Decimal type, it
    seems to come out as a Integer. No "cents" are written to the page.

    Thanks!

    (In VB)

    <code>

    Function CalculateExpended(intBudgetID As Integer) As Decimal

    Dim objConnection As SqlConnection
    Dim cmdSelectData As SqlCommand
    Dim strConnectString As String
    Dim strSQL As String
    Dim decExpendedAmt As Decimal

    strConnectString =
    System.Configuration.ConfigurationSettings.AppSettings("SqlConnection")
    strSQL = "SELECT Stuff....."


    objConnection = New SqlConnection(strConnectString)
    cmdSelectData = New SqlCommand(strSQL, objConnection)

    objConnection.Open()
    decExpendedAmt = cmdSelectData.ExecuteScalar()
    objConnection.Close()

    Return decExpendedAmt

    End Function



    In Template....

    Expended: <%# (CalculateExpended(Container.DataItem("ID"))) %>



    </code>
    D. Shane Fowlkes, May 19, 2005
    #1
    1. Advertising

  2. D. Shane Fowlkes

    Marina Guest

    Here you are relying on however .NET natively formats decimals.
    To format as currency, you function should either do the formatting and
    return a string, or in your script block, you should wrap your call out to
    the function in something that will do the formatting.

    "D. Shane Fowlkes" <> wrote in message
    news:...
    > Hey guys. I have a Repeater and a Template. One of the dataitems calls a
    > helper function. The dataitem sends the record ID to the function and the
    > function runs a complex query and returns a calculation which is a dollar
    > amount. The ID is a "construction project" and the helper function goes
    > and determines how much money has already been spent against the project
    > by querying expenditure tables.
    >
    > The function works fine but how can I format the output to be currency? I
    > also noticed that even though my function returns data of a Decimal type,
    > it seems to come out as a Integer. No "cents" are written to the page.
    >
    > Thanks!
    >
    > (In VB)
    >
    > <code>
    >
    > Function CalculateExpended(intBudgetID As Integer) As Decimal
    >
    > Dim objConnection As SqlConnection
    > Dim cmdSelectData As SqlCommand
    > Dim strConnectString As String
    > Dim strSQL As String
    > Dim decExpendedAmt As Decimal
    >
    > strConnectString =
    > System.Configuration.ConfigurationSettings.AppSettings("SqlConnection")
    > strSQL = "SELECT Stuff....."
    >
    >
    > objConnection = New SqlConnection(strConnectString)
    > cmdSelectData = New SqlCommand(strSQL, objConnection)
    >
    > objConnection.Open()
    > decExpendedAmt = cmdSelectData.ExecuteScalar()
    > objConnection.Close()
    >
    > Return decExpendedAmt
    >
    > End Function
    >
    >
    >
    > In Template....
    >
    > Expended: <%# (CalculateExpended(Container.DataItem("ID"))) %>
    >
    >
    >
    > </code>
    >
    >
    >
    Marina, May 19, 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. Joseph Suprenant

    converting fron unsiged char to int

    Joseph Suprenant, Aug 18, 2003, in forum: C++
    Replies:
    4
    Views:
    562
    Kevin Goodsell
    Aug 19, 2003
  2. ss
    Replies:
    1
    Views:
    1,371
    Gordon Beaton
    Jun 22, 2006
  3. Bill

    Conversion fron signed to unsigned?

    Bill, Sep 13, 2005, in forum: C Programming
    Replies:
    2
    Views:
    357
    Jirka Klaue
    Sep 13, 2005
  4. jainshasha

    to read mails fron inboxes

    jainshasha, Apr 17, 2008, in forum: Java
    Replies:
    3
    Views:
    281
    Roedy Green
    Apr 18, 2008
  5. kevin
    Replies:
    1
    Views:
    359
    Kairi Zikpin
    Jul 21, 2006
Loading...

Share This Page