Solved

formatting a decimal inside repeater

Posted on 2011-02-11
4
801 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

ScreenConnect 6.0 Free Trial

At ScreenConnect, partner feedback doesn't fall on deaf ears. We collected partner suggestions off of their virtual wish list and transformed them into one game-changing release: ScreenConnect 6.0. Explore all of the extras and enhancements for yourself!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How can I build my own IDE using ASP.NET MVC? 2 44
convert html to string 6 34
ASP.NET 5 Templates 2 78
ck editor is taking too much time to be loaded in asp 1 17
Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

773 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