开发者

Bind SSN to telerik grid in formatted way XXX-XX-XXXX instead of XXXXXXXXX

Bind SSN to telerik grid in formatted way XXX-XX-XXXX instead of XXXXXXXXX

Hi All,

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>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜