Solved

How to group number digits from Eval ?

Posted on 2010-08-12
5
328 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

      Install BugTracker on Windows 2008 server Step 1:  Install windows 2008 server 32 bit OS and configure IIS. Step 2:  Install SQL server ( SQL server 2005 or SQL server 2005 Express edition. The installer for 2008  version isn’t very f…
Thoughout my experience working on eCommerce web applications I have seen applications succumbing to increased user demand and throughput. With increased loads the response times started to spike, which leads to user frustration and lost sales. I ha…
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.
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…

744 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

18 Experts available now in Live!

Get 1:1 Help Now