Masking Account number to View only last 4 digits in DevExpress GridViewDataColumn(屏蔽帐号以仅查看 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 中没有这样的原生显示格式功能,它会部分地隐藏某些第一个字符的字符串(a密码掩码可用,但会隐藏所有字符),但是您可以处理 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.
屏蔽核心示例:Fiddle demo
参考:ASPxGridView.CustomColumnDisplayText 事件
相关问题:
ASPxGridView - 如何使用 CustomColumnDisplayText 事件处理程序
这篇关于屏蔽帐号以仅查看 DevExpress GridViewDataColumn 中的最后 4 位数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:屏蔽帐号以仅查看 DevExpress GridViewDataColumn 中的最
基础教程推荐
- C# 9 新特性——record的相关总结 2023-04-03
- 重新排序 WPF TabControl 中的选项卡 2022-01-01
- 在 VB6 或经典 ASP 中使用 .NET 2022-01-01
- 如果条件可以为空 2022-01-01
- 将数据集转换为列表 2022-01-01
- 更新 Visual Studio 中的 DataSet 结构以匹配新的 SQL 数据库结构 2022-01-01
- 获取C#保存对话框的文件路径 2022-01-01
- 从 C# 控制相机设备 2022-01-01
- SonarQube C# 分析失败“不是指针的有效行偏移" 2022-01-01
- Mono https webrequest 失败并显示“身份验证或解密失败" 2022-01-01
