Formatting output fron Helper Function in Template? Syntax?

D

D. Shane Fowlkes

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>
 
M

Marina

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top