evo_x
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#
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#
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'
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("ActiveAd s").ToStri ng()).ToSt ring("#,## #") %>'
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")).T oString("# ,###") %>'
Where is your data coming from and how is it formatted?
Text='<%# Int32.Parse(Eval("ActiveAd
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")).T
Where is your data coming from and how is it formatted?
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: <asp:Label ID="LabelTotalAdsNum" runat="server" Font-Bold="True" Text='<%# ((int)Eval("ActiveAds")).T oString("# ,###") %>'</asp:Label>
Line 55: </p>
Line 56: </div>
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:
Line 54: <asp:Label ID="LabelTotalAdsNum" runat="server" Font-Bold="True" Text='<%# ((int)Eval("ActiveAds")).T
Line 55: </p>
Line 56: </div>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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("ActiveAd