Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How to group number digits from Eval ?

Posted on 2010-08-12
5
Medium Priority
?
339 Views
Last Modified: 2012-05-10
I have this line <asp:Label ID="LabelTotalAdsNum" runat="server" Font-Bold="True"                          Text='<%# Eval("ActiveAds") %>'></asp:Label>

I want the number to be displayed with 3 digits groups, like 89,000 instead of 89000

How can I accomplish this?

I use Visual Studio 2010 / ASP.NET / C#
0
Comment
Question by:evo_x
  • 3
  • 2
5 Comments
 
LVL 2

Expert Comment

by:GLoad
ID: 33425953
Try using  Text='<%# Eval("ActiveAds").ToString("#,###") %>'

You might need to also check that your datavalue (ie ActiveAds) is an numeric type like an int or a long. If it isn't you might need to parse it first to access the numeric format strings.

So.. if the above doesn't work, try the following:

 Text='<%# Int32.Parts(Eval("ActiveAds")).ToString("#,###") %>'
0
 
LVL 2

Author Comment

by:evo_x
ID: 33426042
it does not work...
the first line generates this error:
CS1501: No overload for method 'ToString' takes 1 arguments


and the second line generates this error:
CS0117: 'int' does not contain a definition for 'Parts'
0
 
LVL 2

Expert Comment

by:GLoad
ID: 33426126
I've tested this in a repeater using the code

 Text='<%# Int32.Parse(Eval("ActiveAds").ToString()).ToString("#,###") %>'

and it works fine. Not sure what your underlying datatype is, but I'm sure that works. If you don't want to eval to a string, then convert back to an Int, it can also be cast using:

 Text='<%# ((int)Eval("ActiveAds")).ToString("#,###") %>'

Where is your data coming from and how is it formatted?
0
 
LVL 2

Author Comment

by:evo_x
ID: 33426193
The data is comming from cached ObjectDataSource I am not sure what kind of data does that return.

I have tried again your last suggestions, but I still get errors
Parser Error Message: The server tag is not well formed.

Source Error:


Line 52:                     <p>
Line 53:                         <asp:Label ID="LabelTotalAds" runat="server" Font-Bold="True" Text="Total Ads:" ForeColor="#660033"></asp:Label>
Line 54: &nbsp;<asp:Label ID="LabelTotalAdsNum" runat="server" Font-Bold="True" Text='<%# ((int)Eval("ActiveAds")).ToString("#,###") %>'</asp:Label>
Line 55:                     </p>
Line 56:                     </div>
 
0
 
LVL 2

Accepted Solution

by:
GLoad earned 2000 total points
ID: 33426457
You've dropped the end of your label tag there.

<asp:Label ID="LabelTotalAdsNum" runat="server" Font-Bold="True" Text='<%# ((int)Eval("ActiveAds")).ToString("#,###") %>'</asp:Label>

should be

<asp:Label ID="LabelTotalAdsNum" runat="server" Font-Bold="True" Text='<%# ((int)Eval("ActiveAds")).ToString("#,###") %>'></asp:Label>
0

Featured Post

 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

Question has a verified solution.

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

While opting for any web-to-print solution, you need to discuss with your team and some of your end users and know their opinions about your decisions. In this article we list down some questions you need to ask yourself.
Hello there! As a developer I have modified and refactored the unit tests which was written by fellow developers in the past. On the course, I have gone through various misconceptions and technical challenges when it comes to implementation. I would…
This video teaches users how to migrate an existing Wordpress website to a new domain.
Wufoo.com provides powerful tools for surveying targeted groups, and utilizing data from completed surveys to find trends, discover areas of demand or customer expectation, and make business decisions on products or services.
Suggested Courses

972 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