c# - Grab the first to fourth characters from string and change it to other character in Gridview -


i have gridview numbers of columns. in 1 of columns, have users' contact number, want mask first 4 number. there way it?

for example:

123456 

i want have last 2 numbers visible. thus, output be

xxxx56 

is there way?

<asp:gridview id="gvattendance" runat="server" autogeneratecolumns="false" cssclass="table table-bordered table-hover table-striped gvv">     <columns>           <asp:boundfield datafield="usercn" headertext="contact number" />     </columns> </asp:gridview> 

the easiest way can think of creating function returns anonymized string inside gridview itemtemplate.

<asp:templatefield>     <itemtemplate>         <%# anonymizestring(eval("usercn").tostring()) %>     </itemtemplate> </asp:templatefield> 

and function

public string anonymizestring(string input) {     if (!string.isnullorempty(input) && input.length > 5)     {         return "xxxx" + input.substring(4, 2);     }     else     {         return input;     } } 

or one-liner in gridview

 <%#  (!string.isnullorempty(eval("usercn").tostring()) && eval("usercn").tostring().length > 5) ? "xxxx" + eval("usercn").tostring().substring(4, 2) : eval("usercn").tostring() %> 

Comments

Popular posts from this blog

account - Script error login visual studio DefaultLogin_PCore.js -

xcode - CocoaPod Storyboard error: -