Click here to Skip to main content
16,016,570 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have datatable to view in gridview. Now i need to mask 1st 6 digit of "AdminNumber" column content to "XXXXXX895".

DataTable Input:

AdminNumber Name
245637895 sham
124563789 Ram

I need Datatable output as:

AdminNumber Name
XXXXXX895 Sham
XXXXXX789 Ram


I have tried, but iam getting format the string option:

gridview.DataSource = dtSource;
     gridview.Columns[0].FormatString = "######";


Iam getting wrong output as

AdminNumber Name
XXXXXXXXX Sham
XXXXXXXXX Ram

What I have tried:

gridview.DataSource = dtSource;
     gridview.Columns[0].FormatString = "######";
Posted
Updated 7-Jun-18 8:52am
Comments
[no name] 1-Jun-18 11:43am    
Maybe do this better in your SQL allready if possible?

 
Share this answer
 
Comments
Maciej Los 7-Jun-18 14:33pm    
5ed!
In addition to solution#1 by Gerry Schmitz[^], i'd like to provide C# example, how to create masked column ;)

C#
dt.Columns.Add("MaskedNumber", typeof(string));
dt.Columns["MaskedNumber"].Expression = "'XXX-XX-'+SUBSTRING(CONVERT(Number, System.String),6,4)";


result:
Number    FName  LastName MaskedNumber
781637895 sham   C        XXX-XX-7895 
558563789 Ram    M        XXX-XX-3789 


Finally, you have to hide DataGridView's column[0] ;)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900