如何用不同于数据源的文本过滤ASPxGridView [英] How to filter ASPxGridView by text that is different from data source

查看:118
本文介绍了如何用不同于数据源的文本过滤ASPxGridView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的网页上有一个DevExpress AspGridView,并且正在使用包含的过滤器行。我遇到的问题是,我正在将显示文本的值从整数更改为数组中的某个对应字符串(该整数成为数组索引),但是过滤器行未按新的显示文本值进行排序。在过滤器行中键入内容时,它将尝试搜索整数而不是字符串。

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())];
            }
        };


推荐答案

通过指定自定义网格单元格的文本ASPxGridView.CustomColumnDisplayText 事件(而不是 ASPxGridView.HtmlDataCellPrepared 一个),并将相应列的Settings.FilterMode属性设置为DisplayText:

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

这篇关于如何用不同于数据源的文本过滤ASPxGridView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆