Bind SSN to telerik grid in formatted way XXX-XX-XXXX instead of XXXXXXXXX
I am binding the SSN value t开发者_运维知识库o the grid using ASP.net which i am getting from the SQL database. I have used the below code to format the SSN. But i could not get the specified format.
Please help me to find out the solution.
I had trouble with this too and the way I overcame it was by creating a function
Public Shared Function FormatSSN(sSSN As String) As String
sSSN = sSSN.Replace(" ", "").Replace("-", "")
If sSSN = "" OrElse sSSN.Length <> 9 Then
sSSN = "000000000"
End If
If sSSN.Length = 9 Then
sSSN = sSSN.Substring(0, 3) & "-" & sSSN.Substring(3, 2) & "-" & sSSN.Substring(5, 4)
End If
Return sSSN
End Function
Then you can call it like this:
<asp:Label ID="LblSSN" runat="server" text='<%FormatSSN(Eval("SSN"))'></asp:Label>
精彩评论