Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How to group number digits from Eval ?

Posted on 2010-08-12
5
Medium Priority
?
337 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
[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
  • 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

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

A publishing tool, a Version Control System, or a Collaboration Platform! These can be some of the defining words for the two very famous web-hosting Git repositories: Bitbucket and Github. Git is widely used amongst the programmers and developers f…
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.
This video teaches viewers how to create their own website using cPanel and Wordpress. Tutorial walks users through how to set up their own domain name from tools like Domain Registrar, Hosting Account, and Wordpress. More specifically, the order in…
Learn how to set-up custom confirmation messages to users who complete your Wufoo form. Include inputs from fields in your form, webpage redirects, and more with Wufoo’s confirmation options.

661 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