Link to home
Start Free TrialLog in
Avatar of evo_x
evo_xFlag for Romania

asked on

How to group number digits from Eval ?

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#
Avatar of GLoad
GLoad

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("#,###") %>'
Avatar of evo_x

ASKER

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'
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?
Avatar of evo_x

ASKER

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>
 
ASKER CERTIFIED SOLUTION
Avatar of GLoad
GLoad

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial