Solved

format currency in a repeater

Posted on 2007-12-02
8
5,475 Views
Last Modified: 2013-11-07
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
0
Comment
Question by:ANAT2403
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 12

Expert Comment

by:Mortaza Doulaty
ID: 20391607
You can use:

<%#String.Format("{0:C}", Eval("[Amount_mny]"))%>

Open in new window

0
 
LVL 14

Expert Comment

by:Dustin Hopkins
ID: 20391671
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("MinPrice")) %>' ></asp:Label>

Code behind:
public object formatcurrency(double amount)
{
    return amount.ToString("c");
}
0
 
LVL 4

Expert Comment

by:hamidovt
ID: 20394313
<%# Eval("MinPrice", "{0:C}")%>   should work fine,  just add HtmlEncode="false" to your datagrid, repeater or whatever control you have...
0
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 

Accepted Solution

by:
ANAT2403 earned 0 total points
ID: 20396024
Hi,
In the repeater I did not find an option of HtmlEncode="false"  but I manage to solve the problem in the
code behind like this:
            Label lblMax = (Label)e.Item.FindControl("lblMaxPrice");
            string maxpStr = String.Format("{0:C}", decimal.Parse(lblMax.Text));
            lblMax.Text = maxpStr.ToString();
Anat
0
 
LVL 12

Expert Comment

by:Mortaza Doulaty
ID: 20397703
This would certainly solve your problem:

<%#string.Format("{0:C}", Eval("[Amount_mny]"))%>

Open in new window

0
 

Author Comment

by:ANAT2403
ID: 20401484
Hi,
Sorry but still only the dealing in code behind work.
Anat
0
 
LVL 1

Expert Comment

by:Vee_Mod
ID: 20572467
Closed, 500 points refunded.
Vee_Mod
Community Support Moderator
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Selenium: Transitioning from unit testing to automated testing 4 62
ModalPopup  question 22 38
Aspx calendar pop up control 3 28
Connect Gridview column to Textbox in C# 2 41
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question