Back to Devexpress

How to: Specify Custom Display Text for Data Cells

aspnet-3766-components-grid-view-examples-how-to-provide-custom-display-text-for-data-cells.md

latest1.0 KB
Original Source

How to: Specify Custom Display Text for Data Cells

  • Nov 18, 2021

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:

csharp
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";
}
vb
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