Question

alt textHi All,

I am binding the SSN value to 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.

Was it helpful?

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>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top