Formatting columns in the DevExpress ASPxGridView?

Donny picture Donny · Oct 20, 2011 · Viewed 21.2k times · Source

Does anyone know how I could format columns in the DevExpress ASPxGridView. What I have is a xml file that is generated daily from an xml file. What I would like to do is format columns for specific values, for example, a column with measurements, I want to add trailing zeros if these are not filled, i.e. 1.2 to 1.200. I have only come across examples done in the ASPX page and have built my columns in code. Please assist with the simplest solutions or property, thanks.

Answer

Emmanuel N picture Emmanuel N · Oct 20, 2011

In your .aspx page you can do this to format your column to dollar amount with 0 decimal place

  <dx:GridViewDataTextColumn FieldName="YourFieldName" VisibleIndex="1" Name="Displayame">
      <PropertiesTextEdit DisplayFormatString="${0}" />
  </dx:GridViewDataTextColumn>

In Code behind bind CellEditorInitialize to a custome event handler something like:

 ASPxGridViewData.CellEditorInitialize+=new DevExpress.Web.ASPxGridView.ASPxGridViewEditorEventHandler(ASPxGridViewData_CellEditorInitialize);
protected void ASPxGridViewData_CellEditorInitialize(object sender, ASPxGridViewEditorEventArgs e){
if (e.Column.FieldName == "YourFieldName") {
    e.Editor.Value = string.Format("${0}", e.Value);
}}