ASPxGridView.CustomColumnDisplayText Event
Enables you to specify the display text for a cell.
Namespace: DevExpress.Web
Assembly: DevExpress.Web.v19.2.dll
Declaration
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. |
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 when its data is printed or exported.
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.
Note
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.
Online Demo
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:
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";
}