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.
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
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]
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