aspnet-devexpress-dot-web-dot-aspxgridview-cadc1557.md
Enables you to specify the display text for a cell.
Namespace : DevExpress.Web
Assembly : DevExpress.Web.v25.2.dll
NuGet Package : DevExpress.Web
public event ASPxGridViewColumnDisplayTextEventHandler CustomColumnDisplayText
Public Event CustomColumnDisplayText As ASPxGridViewColumnDisplayTextEventHandler
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. |
The CustomColumnDisplayText event occurs for bound and unbound columns. This event allows you to specify the text that is displayed in the grid.
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.
CustomColumnDisplayText event is not in effect for template columns.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.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.
<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;
}
}
Imports DevExpress.Web
Protected Sub grid_CustomColumnDisplayText(ByVal sender As Object, ByVal e As ASPxGridViewColumnDisplayTextEventArgs)
If e.Column.FieldName = "ProductAmount" AndAlso Convert.ToDecimal(e.Value) = 0 Then
e.DisplayText = "none"
End If
End Sub
Protected Sub grid_BeforeExport(ByVal sender As Object, ByVal e As ASPxGridBeforeExportEventArgs)
Select Case e.ExportTarget
Case ExportTarget.Xls
Dim optionsXls As XlsExportOptions = TryCast(e.ExportOptions, XlsExportOptions)
optionsXls.TextExportMode = TextExportMode.Text
Case ExportTarget.Xlsx
Dim optionsXlsx As XlsxExportOptions = TryCast(e.ExportOptions, XlsxExportOptions)
optionsXlsx.TextExportMode = TextExportMode.Text
Case Else
End Select
End Sub
<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);
}
Imports DevExpress.Web
Protected Sub grid_CustomColumnDisplayText(ByVal sender As Object, ByVal e As ASPxGridViewColumnDisplayTextEventArgs)
If e.Column.FieldName = "ProductAmount" AndAlso Convert.ToDecimal(e.Value) = 0 Then
e.DisplayText = "none"
End If
End Sub
Protected Sub button_Click(ByVal sender As Object, ByVal e As EventArgs)
Dim exportOptions = New DevExpress.XtraPrinting.XlsxExportOptionsEx()
exportOptions.TextExportMode = DevExpress.XtraPrinting.TextExportMode.Text
grid.ExportXlsxToResponse(exportOptions)
End Sub
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";
}
Protected Sub ASPxGridView1_CustomColumnDisplayText(ByVal sender As Object,_
ByVal e As DevExpress.Web.ASPxGridViewColumnDisplayTextEventArgs)_
Handles ASPxGridView1.CustomColumnDisplayText
If e.Column.FieldName = "UnitsOnOrder" Then
If Convert.ToInt32(e.Value) = 0 Then
e.DisplayText = "empty"
End If
End If
End Sub
See Also