Datatable包含多个列,它将以gridview显示。现在我需要屏蔽" Number"的整个列的前6位数字。内容格式如" XXX-XX-7895"。
DataTable输入:
Number FName LastName
781637895 sham C
558563789 Ram M
我需要数据表输出:
Number FName LastName
XXX-XX-7895 sham C
XXX-XX-3789 Ram M
我尝试过使用 CellFormatting 事件,使用没有" - "字符。我需要" - "要包含的字符。
private void gridview_transformation_CellFormatting(object sender, CellFormattingEventArgs e)
{
if (e.ColumnIndex == 7 )
{
string adminNumber = e.CellElement.Value.ToString();
int length = Math.Min(5, adminNumber.Length);
adminNumber = new string('X', length) + adminNumber.Substring(length);
e.CellElement.Value = adminNumber;
}
我得到的输出(输出错误)
Number FName LastName
XXXXX7895 sham C
XXXXX3789 Ram M
请帮助获得正确的格式。
答案 0 :(得分:1)
int length = Math.Min(4, adminNumber.Length);
adminNumber = "XXX-XX-" + adminNumber.Substring(length);