Masking Account number to View only last 4 digits in DevExpress GridViewDataColumn

≡放荡痞女 提交于 2019-12-02 15:37:45

问题


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>

回答1:


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;
}

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.

Masking core example: Fiddle demo

Reference: ASPxGridView.CustomColumnDisplayText Event

Related issue:

ASPxGridView - How to use the CustomColumnDisplayText event handler




回答2:


Masking in for only input form, maybe you can use substring in serverside if you want view only 4 digit

Source : https://demos.devexpress.com/aspxeditorsdemos/Features/MaskedInput.aspx



来源:https://stackoverflow.com/questions/52586528/masking-account-number-to-view-only-last-4-digits-in-devexpress-gridviewdatacolu

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!