This is a migrated thread and some comments may be shown as answers.

Formatting of Phone Numbers

2 Answers 1022 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Brian Mains
Top achievements
Rank 1
Brian Mains asked on 07 Dec 2010, 03:50 PM
Hello,

I'm  binding this data (a phone number):

5555015555

to a radgrid column.  I need it to appear as:

(555) 501-5555

But I tried using a format string and it didn't work.  Is the only way to format it through code?

Thanks.

2 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 08 Dec 2010, 05:59 AM
Hello Brian,

The DataFormatString property for phone number will only works if your data type in that column is of type like numeric. This approach does not work if you have data type as string.
One option is converting the data type of that column to something that can be formatted using the format string and do it from code behind.
Another option is using GridTemplateColumn instead of GridBoundColumn and format it like below.

ASPX:
<telerik:GridTemplateColumn HeaderText="Phone Number">
   <ItemTemplate>
        <%# string.Format("{0:(###)###-####}", Convert.ToInt64(Eval("phone"))) %>
   </ItemTemplate>
</telerik:GridTemplateColumn>

Thanks,
Princy.
0
J2K
Top achievements
Rank 1
answered on 02 Apr 2013, 11:34 AM
The simpliest solution I've found is

1) In the datasource, convert the telephone field/column to a big int if it's now stored as string/char: Convert(bigint,Telephone) as Telephone

2) In the Radgrid markup, add this: DataType="System.Int64"    DataFormatString ="{0:(###) ###-####}"



Tags
Grid
Asked by
Brian Mains
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
J2K
Top achievements
Rank 1
Share this question
or