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

前端 未结 2 1874
盖世英雄少女心
盖世英雄少女心 2021-01-27 07:16

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

相关标签:
2条回答
  • 2021-01-27 07:30

    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

    0 讨论(0)
  • 2021-01-27 07:45

    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

    0 讨论(0)
提交回复
热议问题