|
Rank: Member Groups: Member
Joined: 9/6/2007 Posts: 29
|
I have two columns of float data I am trying to display in a grid. One column is in a StaticColumn and the other is in a TextBoxColumn. I would like the data to be displayed as 9(9)*.99 (eg 0.00, 12.34, 12345.67. 123456.78, etc) I went to the documentation on DataFormat to see what formats are supported and it was slightly less than helpful Gets or sets the data format for this column.
Code: C#
public string DataFormat {get; set;}
I could not find any examples of DatFormat uses. Any ideas on how to set the DataFormat string? Thanks
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,194
|
Hi,
The DataFormat is used by string.Format to get the item text from item value:
itemText = string.Format(DataFormat, itemValue);
So it will only take whatever that string.Format takes, for example, "{0:0.00}". One thing that you want to pay extra attention is, if you use the Grid in client mode, you want to use the formatted string as data value instead of relying on DataFormat because DataFormat is not used on the client side. Using server or callback mode does not have this limitation.
Thanks
|
|
Rank: Member Groups: Member
Joined: 9/6/2007 Posts: 29
|
I am not sure what you mean. The way I have things set up is as follows (I am only showing snippets):
Code: HTML/ASPX
<eo:Grid ID="_PayrollGrid" runat="server"
RunningMode="Server"
...
>
...
<eo:StaticColumn DataField="PaidHours"
HeaderText="Pay Hours"
DataFormat="{0:0.00}"
DataType="float" />
<eo:TextBoxColumn DataField="ShiftDifferential"
HeaderText="Shift Differential"
Width="150"
DataFormat="{0:0.00}"
DataType="float" />
</eo:Grid>
On the code behind side I have:
Code: C#
_PayrollGrid.DataSource = PayrollLineItems.Get(
employee.EmployeeID,
new DateTime(2007, 11, 18),
new DateTime(2007, 11, 25)
);
_PayrollGrid.DataBind();
I am not sure, based on your warning, how being in Server versus Client mode changes the display, but setting the RunningMode has had no effect. Do I need to override the OnDataBinding to format the columns appropriately?
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,194
|
Hi, This appears to be a bug. We will get it addressed as soon as possible. For now the easiest way to work around this is to modify your data source, not through OnDataBinding. For example:
Code: C#
public class PayrollLineItem
{
//This is the original property
public float PaidHours
{
get { return m_PaidHours; }
}
//This is the properly formatted value used for the Grid
public string PaidHoursAsString
{
get { return string.Format("{0:0.00}", PaidHours); }
}
}
You will then change your DataField from PaidHours to PaidHoursAsString. If it is not convenient for you to change your data source object, you can define a new object wraps around your data source object:
Code: C#
public class GridDataItem
{
private PayrollLineItem m_Data;
public GridDataItem(PayrollLineItem data)
{
m_Data = data;
}
//properly formatted based on the original data
public string PaidHours
{
get { return string.Format("{0:0.00}", m_Data.PaidHours); }
}
}
And then use an array of GridDataItem instead of PayrollLineItem as data source. Thanks
|
|