grid format

T

Tom

In my grid how can I get $229 to show instead of 228.889?

I have the column set to string.format("{0:c}") but its still showing
$228.88 and I want $229 to show
 
G

George Ter-Saakov

{0:c} is affected by you system settings in windows.
I found it the best to create some static (C#, Shared in VB) function and
call it...

Example.

class clsHelper
{
public static string GetMoney(object objValue)
{
decimal dTotal = (decimal)objValue;
return dTotal.ToString("$00");
}
}

Then use in in your DataGrids (or anywere on .aspx)
<%# clsHelper.GetMoney( DataBinder.Eval(Container.DataItem, "Total")) %>

Then you can change your formatting anywere in a project with quick simple
change.

PS: Go here for all formatting options
http://technet.microsoft.com/en-us/library/0c899ak8.aspx

George.
 
A

Angel

You are not being very explicit. so I will make some assumption
using a sqldatasource or objdatasource

for the specific column:
htmlencdoe= false and
DataFormatString = {0:c}

This should take care of it but If you are doing something crazy like
dynamically creating your column you must make the column datatype something
other than a string otherwise the above will have no effect
 
A

Angel

Notice that in my VS2008 machine HtmlEncode has been fixe and is no longer
required even if you are targetting Framework 2.0

Another trick is to setup your query to produce a formatted output or use a
view. Then the issue will not affect you anymore.

Formatting is not limited to {0:c} You could also do {0:##0.00}

Hope this helps
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,181
Messages
2,570,970
Members
47,537
Latest member
BellCorone

Latest Threads

Top