Formatting of Phone Numbers

3 posts, 0 answers
  1. Brian Mains
    Brian Mains avatar
    485 posts
    Member since:
    Oct 2008

    Posted 07 Dec 2010 Link to this post


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


    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?

  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 07 Dec 2010 Link to this post

    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.

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

  3. DevCraft R3 2016 release webinar banner
  4. J2K
    J2K avatar
    33 posts
    Member since:
    Sep 2005

    Posted 02 Apr 2013 Link to this post

    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:(###) ###-####}"

Back to Top