ANAT2403
asked on
format currency in a repeater
In ASP.NET 2.0 with C# I have a repeater that is bounded to a datatanle.
I have there inside a <td> the following field:
<%# Eval("MinPrice")%>
If I write it like this: <%# Eval("MinPrice", "{0:C}")%> it does not show the currency sign
so I want to prepare it in the code behind in the repeater ItemDataBound event.
If I do there:
string AmountStr1 = String.Format("{0:C}", decimal.Parse(tempAmount)) ;
I get the appropriate value. but in the databound event of the repeater I know how to deal with values from controls like button, hyperlink, hiddenfiels. but what do I do with value that is a field in the repeater but has no control?
How do I work on it and return it to the repeater?
Thankyou
Anat
I have there inside a <td> the following field:
<%# Eval("MinPrice")%>
If I write it like this: <%# Eval("MinPrice", "{0:C}")%> it does not show the currency sign
so I want to prepare it in the code behind in the repeater ItemDataBound event.
If I do there:
string AmountStr1 = String.Format("{0:C}", decimal.Parse(tempAmount))
I get the appropriate value. but in the databound event of the repeater I know how to deal with values from controls like button, hyperlink, hiddenfiels. but what do I do with value that is a field in the repeater but has no control?
How do I work on it and return it to the repeater?
Thankyou
Anat
Since you want to do this in the code behind, instead of using the event create a function and send the eval to it.
Front End
<asp:Label ID="Label1" runat="server" Text='<%# formatcurrency(Eval("MinPr ice")) %>' ></asp:Label>
Code behind:
public object formatcurrency(double amount)
{
return amount.ToString("c");
}
Front End
<asp:Label ID="Label1" runat="server" Text='<%# formatcurrency(Eval("MinPr
Code behind:
public object formatcurrency(double amount)
{
return amount.ToString("c");
}
<%# Eval("MinPrice", "{0:C}")%> should work fine, just add HtmlEncode="false" to your datagrid, repeater or whatever control you have...
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
This would certainly solve your problem:
<%#string.Format("{0:C}", Eval("[Amount_mny]"))%>
ASKER
Hi,
Sorry but still only the dealing in code behind work.
Anat
Sorry but still only the dealing in code behind work.
Anat
Closed, 500 points refunded.
Vee_Mod
Community Support Moderator
Vee_Mod
Community Support Moderator
Open in new window