屏蔽帐号以仅查看DevExpress GridViewDataColumn中的最后4位数字 [英] Masking Account number to View only last 4 digits in DevExpress GridViewDataColumn

查看:187
本文介绍了屏蔽帐号以仅查看DevExpress GridViewDataColumn中的最后4位数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要添加一个Mask / DisplayFormatString来仅查看DevExpress GridViewDataColumn中的最后4位数字。例如,如果真实帐号为 123456789 。然后它应显示为 ***** 6789
您能帮我吗?

I need to add a Mask/DisplayFormatString to view only last 4 digits in DevExpress GridViewDataColumn. As an example if the real account number is 123456789. Then it should display as *****6789. Can you please help me with this.

<dx:GridViewDataColumn Caption="Bank Account Number" FieldName="BankAccountNumber"></dx:GridViewDataColumn>


推荐答案

据我所知,没有这种本机显示 ASPxGridView 中的格式功能,它会部分掩盖某些前几个字符的字符串(有密码掩码,但会掩盖所有字符),但是您可以处理 ASPxGridView。 CustomColumnDisplayText 事件可通过以下解决方法产生自定义遮罩:

As far as I know there is no such native display format feature in ASPxGridView which obscures a string partially for certain first characters (a password mask is available but obscures all characters), however you can handle ASPxGridView.CustomColumnDisplayText event to produce custom masking with this workaround:

protected void ASPxGridView1_CustomColumnDisplayText(object sender, DevExpress.Web.ASPxGridViewColumnDisplayTextEventArgs e)
{
    // check column name first
    if (e.Column.FieldName != "BankAccountNumber")
        return;

    // get column values for BankAccountNumber
    string value = e.Value.ToString();

    // set asterisk to hide first n - 4 digits
    string asterisks = new string('*', value.Length - 4);

    // pick last 4 digits for showing
    string last = value.Substring(value.Length - 4, 4);

    // combine both asterisk mask and last digits
    string result = asterisks + last;

    // display as column text
    e.DisplayText = result;
}

侧面注:如参考所述,通过此事件提供的文本将在打印或导出 ASPxGridView 时使用,可能需要单独的 ASPxGridView 实例以多种格式导出或打印。

Side Note: As the reference stated, the text provided via this event will be used when the ASPxGridView is printed or exported, probably you need separate ASPxGridView instance for export in multiple formats or printing.

伪装核心示例:小提琴演示

参考: ASPxGridView.CustomColumnDisplayText事件

相关问题:

ASPxGridView-如何使用CustomColumnDisplayText事件处理程序

这篇关于屏蔽帐号以仅查看DevExpress GridViewDataColumn中的最后4位数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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