Skip to main content
Tab

ASPxGridView.CustomColumnDisplayText Event

Enables you to specify the display text for a cell.

Namespace: DevExpress.Web

Assembly: DevExpress.Web.v23.2.dll

NuGet Package: DevExpress.Web

Declaration

public event ASPxGridViewColumnDisplayTextEventHandler CustomColumnDisplayText

Event Data

The CustomColumnDisplayText event's data class is ASPxGridViewColumnDisplayTextEventArgs. The following properties provide information specific to this event:

Property Description
Column Gets the data column that contains the cell currently being processed.
DisplayText Enables you to set a custom text for the cell currently being processed. Inherited from ASPxGridColumnDisplayTextEventArgs.
EncodeHtml Gets or sets a value that specifies whether the cell display text keeps any of its values that are HTML as HTML, or instead, strips out the HTML markers. Inherited from ASPxGridColumnDisplayTextEventArgs.
Kind Gets the type of operations with grid data. Inherited from ASPxGridColumnDisplayTextEventArgs.
Value Gets the edit value of the cell currently being processed. Inherited from ASPxGridColumnDisplayTextEventArgs.
VisibleIndex Gets the visible index of the data item (row, card or record) where the processed cell resides. Inherited from ASPxGridColumnDisplayTextEventArgs.
VisibleRowIndex Obsolete. Gets the visible index of the data row where the processed cell resides.

The event data class exposes the following methods:

Method Description
GetFieldValue(Int32, String) Returns the value of the specified data source field in the specified data item (row, card or record). Inherited from ASPxGridColumnDisplayTextEventArgs.
GetFieldValue(String) Returns the value of the specified data source field in the current data item (row, card or record). Inherited from ASPxGridColumnDisplayTextEventArgs.

Remarks

The CustomColumnDisplayText event occurs for bound and unbound columns. This event allows you to specify the text that is displayed in the grid.

Run Demo: Data Binding

The CustomColumnDisplayText event fires in the following cases:

  • While the control’s hierarchy is building.

  • When you sort or filter a grid by display text (the GridDataColumnSettings.FilterMode or the ASPxGridBehaviorSettings.SortMode property is set to DisplayText). In this case, the rows’ visible indexes are not taken into account and the GetFieldValue(int visibleRowIndex, string fieldName) method returns -1.

Limitations

  • The CustomColumnDisplayText event is not in effect for template columns.
  • The CustomColumnDisplayText events is not in effect for the GridViewDataCheckColumn column as the grid filters only the column values and ignores its display text. To specify a custom display text for this column, use the DisplayTextChecked and DisplayTextUnchecked properties.

Export Display Text

When exporting data in XLS or XLSX format, the ASPxGridView control exports cell values. If you need to export display text specified in the CustomColumnDisplayText event handler set the TextExportMode property of the XlsExportOptionsEx or XlsxExportOptionsEx object to Text.

Default Export Commands

<dx:ASPxGridView ID="grid" runat="server" DataSourceID="CustomerReportsDataSource"
    OnCustomColumnDisplayText="grid_CustomColumnDisplayText">
    <SettingsExport EnableClientSideExportAPI="true"/>
    <SettingsContextMenu Enabled="true">
        <RowMenuItemVisibility ExportMenu-Visible="true" />
    </SettingsContextMenu>
    <!--...-->
using DevExpress.Web;

protected void grid_CustomColumnDisplayText(object sender, ASPxGridViewColumnDisplayTextEventArgs e) {
    if (e.Column.FieldName == "ProductAmount" && Convert.ToDecimal(e.Value) == 0) {
        e.DisplayText = "none";
    }
}

protected void grid_BeforeExport(object sender, ASPxGridBeforeExportEventArgs e) {
    switch(e.ExportTarget) {
        case ExportTarget.Xls:
            XlsExportOptions optionsXls = e.ExportOptions as XlsExportOptions;
            optionsXls.TextExportMode = TextExportMode.Text;
            break;
        case ExportTarget.Xlsx:
            XlsxExportOptions optionsXlsx = e.ExportOptions as XlsxExportOptions;
            optionsXlsx.TextExportMode = TextExportMode.Text;
            break;
        default:
            break;
    }
}

Export Methods

<dx:ASPxButton ID="ASPxButton1" runat="server" Text="Export to XLSX" OnClick="button_Click" />
<dx:ASPxGridView ID="grid" runat="server" DataSourceID="CustomerReportsDataSource"
    OnCustomColumnDisplayText="grid_CustomColumnDisplayText" />
using DevExpress.Web;

protected void grid_CustomColumnDisplayText(object sender, ASPxGridViewColumnDisplayTextEventArgs e) {
    if (e.Column.FieldName == "ProductAmount" && Convert.ToDecimal(e.Value) == 0) {
        e.DisplayText = "none";
    }
}

protected void button_Click(object sender, EventArgs e) {
    var exportOptions = new DevExpress.XtraPrinting.XlsxExportOptionsEx();
    exportOptions.TextExportMode = DevExpress.XtraPrinting.TextExportMode.Text;
    grid.ExportXlsxToResponse(exportOptions);
}

Example

This example demonstrates how to display the “empty” string within the Units On Order column’s cells if they contain zero values.

The image below shows the result:

CustomColumnDisplayText

protected void ASPxGridView2_CustomColumnDisplayText(object sender,
    DevExpress.Web.ASPxGridViewColumnDisplayTextEventArgs e) {
    if (e.Column.FieldName != "UnitsOnOrder") return;
    if (Convert.ToInt32(e.Value) == 0)
        e.DisplayText = "empty";
}
See Also