2

I have a DevExpress AspGridView on my webpage and I am using the filter row that is included. The problem I am having is that I am changing the value of the display text from an integer to some corresponding string in an array (the integer becomes the array index), however the filter row doesn't sort by the new display text value. When typing something into the filter row, it tries to search for integers rather than strings.

Here is the code used to change the text in the cell

gv.HtmlDataCellPrepared += (sender, e) =>
        {
            if (e.DataColumn.FieldName == "FOO_STATUS")
            {
                e.Cell.Text = STATUS[int.Parse(e.GetValue("FOO_STATUS").ToString())];
            }
        };
Mikhail
  • 9,186
  • 4
  • 33
  • 49
ThinkLink99
  • 43
  • 2
  • 12
  • Why did not you use the DevEx support center? Did you try to search, btw? – Mikhail Sep 24 '18 at 19:25
  • @Mikhail I did try to search and to be honest I'm trying to meet a tight deadline and figured I'd get a faster repsone from SO than DevExpress. – ThinkLink99 Sep 24 '18 at 19:29

1 Answers1

3

Specify custom grid cells' text via the ASPxGridView.CustomColumnDisplayText event (instead of the ASPxGridView.HtmlDataCellPrepared one) and set the corresponding column's Settings.FilterMode property to DisplayText:

<dx:ASPxGridView ... OnCustomColumnDisplayText="OnCustomColumnDisplayText">
    <Columns>
        ...
        <dx:GridViewDataSpinEditColumn FieldName="FOO_STATUS">
            <Settings FilterMode="DisplayText" />
        </dx:GridViewDataSpinEditColumn>
    </Columns>
</dx:ASPxGridView>

//CS    
protected void OnCustomColumnDisplayText(object sender, ASPxGridViewColumnDisplayTextEventArgs e) {
    if (e.Column.FieldName == "FOO_STATUS") {
        e.DisplayText = STATUS[int.Parse(e.GetFieldValue("FOO_STATUS").ToString())];
    }
}

'VB
Protected Sub OnCustomColumnDisplayText(ByVal sender As Object, ByVal e As ASPxGridViewColumnDisplayTextEventArgs)
    If e.Column.FieldName Is "FOO_STATUS" Then
        e.DisplayText = STATUS(Integer.Parse(e.GetFieldValue("FOO_STATUS").ToString()))
    End If
End Sub
Mikhail
  • 9,186
  • 4
  • 33
  • 49