Solved

How to group number digits from Eval ?

Posted on 2010-08-12
5
334 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 500 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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Suggested Solutions

What is Node.js? Node.js is a server side scripting language much like PHP or ASP but is used to implement the complete package of HTTP webserver and application framework. The difference is that Node.js’s execution engine is asynchronous and event…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Use Wufoo, an online form creation tool, to make powerful forms. Learn how to selectively show certain fields based on user input using rules to gather relevant information and data from your forms. The rules feature provides you with an opportunity…
Use Wufoo, an online form creation tool, to make powerful forms. Learn how to choose which pages of your form are visible to your users based on their inputs. The page rules feature provides you with an opportunity to create if:then statements for y…

734 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