grid format

  • Thread starter Thread starter Tom
  • Start date Start date
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
 
{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.
 
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
 
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
 
Back
Top