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

Phone number column formatting(phone number as string)

1 Answer 171 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Mac P
Top achievements
Rank 1
Mac P asked on 09 Aug 2010, 08:23 PM
Hi,

What is the best way to format the phone number as {0:(###)###-####) for the phone numbers that are string in database.
I cannot use dataformatstring or telerik:maskeditcolumn as both expects the phone number as integer.

I also tried template column and have label's text as format string above but it still displays the plain text.
I want to display the column as ready only and should support sorting.

Any help is appreciated.

Regards

1 Answer, 1 is accepted

Sort by
0
Cori
Top achievements
Rank 2
answered on 09 Aug 2010, 08:54 PM

Hello Mac,

You could try something like this:

if (e.Item is GridDataItem)
        {
            GridDataItem grdItem = (GridDataItem)e.Item;
  
            CallLog callLog = (CallLog)grdItem.DataItem;
  
            // create RadMaskedTextBox
            RadMaskedTextBox txtMaskedTextBox = new RadMaskedTextBox();
            txtMaskedTextBox.Mask = "(###)###-####";
  
            // pass caller phone number to mask and get value with mask applied
            txtMaskedTextBox.Text = callLog.CallerPhoneNumber;
            grdItem["CallerPhoneNumber"].Text = txtMaskedTextBox.TextWithLiterals;
        }

You'll need to cast the DataItem to whatever object you're using, mine is CallLog in this case. Either way, the logic should be the same. I create an instance of the RadMaskedTextBox control and then pass in the phone number and then output the RadMaskedTextbox's TextWithLiterals property to get the formatted phone number.

I hope that helps.
Tags
Grid
Asked by
Mac P
Top achievements
Rank 1
Answers by
Cori
Top achievements
Rank 2
Share this question
or