Posted on
7/12/2011
Storing phone numbers in a table without the dashes and parenthesis sounds like a good idea, until you need to retrieve and format them correctly. As always, reading the documentation - and understanding it - can be time consuming and frustrating. Which it was! But this is what I finally came up with...
This will return (123) 456-7890
public partial class Report1 : Telerik.Reporting.Report
{
public Report1()
{
InitializeComponent();
}
public static string FormatPhoneNumber(string phoneNumber)
{
if (phoneNumber.Length == 10)
{
return "(" + phoneNumber.Substring(0, 3) + ") " +
phoneNumber.Substring(3, 3) + "-" +
phoneNumber.Substring(6);
}
else
{
return "no phone number";
}
}
}
Then in the "Value" property of the text box use the following: =FormatPhoneNumber(Fields.Phone)
Of course, you can modify this and take into consideration that the phone number may not have an area code. But who doesn't use area codes?
9f52c57c-47f0-454f-9028-7a460bc6f17a|0|.0