Solved

formatting a decimal inside repeater

Posted on 2011-02-11
4
796 Views
Last Modified: 2012-05-11
Hi,
I have the repeater below.

The value that InvoiceAmount is giving is:
512.33000 or whatever - it is a decimal.

I need to format it to 2 decimal place.

I have tried:
<%#DataBinder.Eval(Container.DataItem, "InvoiceAmount").ToString("#00.00")%>

but get:
 System.FormatException: Input string was not in a correct format.

What am I doing wrong?
<asp:Repeater ID="rptResults" runat="server" >                                       
                        <ItemTemplate>
                        <tr>
                            <td>                                
                                <%#DataBinder.Eval(Container.DataItem, "RegNumber")%>
                            </td>
                            <td>
                                <%#DataBinder.Eval(Container.DataItem, "SupplierOnInvoice.Name")%>
                            </td>
                            <td>
                                <%#DataBinder.Eval(Container.DataItem, "Payee.Name")%>
                           </td>                               
                           <td>
                                <%#DataBinder.Eval(Container.DataItem, "InvoiceAmount")%>
                           </td>                                                       
                            
                        </tr>            
                        </ItemTemplate>                            
                    </asp:Repeater>

Open in new window

0
Comment
Question by:scm0sml
  • 3
4 Comments
 
LVL 9

Assisted Solution

by:s_chilkury
s_chilkury earned 200 total points
ID: 34871314
Change to:

<%#DataBinder.Eval(Container.DataItem, "InvoiceAmount", "{0:d}")%>
0
 

Author Comment

by:scm0sml
ID: 34871334
System.FormatException: Format specifier was invalid.

Source Error:


Line 187:                           </td>                              
Line 188:                           <td>
Line 189:                                <%#DataBinder.Eval(Container.DataItem, "InvoiceAmount", "{0:d}")%>
Line 190:                           </td>          
 
0
 

Accepted Solution

by:
scm0sml earned 0 total points
ID: 34905464
This works:
<%#DataBinder.Eval(Container.DataItem, "InvoiceAmount", "{0:F2}")%>

found it at it:
http://connect.microsoft.com/VisualStudio/feedback/details/324166/format-specifier-invalid-exception-introduced-by-net-2-0-sp1
0
 

Author Closing Comment

by:scm0sml
ID: 34941233
Go the answer myself.

One answer was correct for an old framework so have given some points.
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
This video discusses moving either the default database or any database to a new volume.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

760 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now