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

Format Telephone # With Extension

3 Answers 47 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Neil N
Top achievements
Rank 1
Veteran
Iron
Neil N asked on 27 Feb 2013, 06:54 PM
I've got a column with telephone numbers, some with extensions, entered via a RadMaskedTextBox with Mask="(###) ###-#### ####".  Is it possible to have a DataFormatString which shows the entries properly? DataFormatString="{0:(###) ###-#### ####}" shifts everything to the right for numbers with no extensions.

3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 1
answered on 28 Feb 2013, 07:38 AM
Hi,

One suggestion is that you can use a MaskedColumn as shown below.
aspx:
<telerik:GridMaskedColumn DataFormatString="{0:(###) -#### ##}" Mask="(###) ###-####" UniqueName="TelephoneNumber" HeaderText="Phone" DataField="Phone" > </telerik:GridMaskedColumn>

Thanks,
Princy
0
Neil N
Top achievements
Rank 1
Veteran
Iron
answered on 02 Mar 2013, 11:40 PM
Weird. Following up on your suggestion I looked at the online demo for GridMaskedColumn which had this code:
<telerik:GridMaskedColumn Mask="(###) ###-####" UniqueName="HomePhone" SortExpression="HomePhone"
    HeaderText="Masked Column" DataField="HomePhone" FooterText="MaskedColumn footer">
    <ItemStyle Width="100px"></ItemStyle>
</telerik:GridMaskedColumn>

My test code:
<telerik:GridBoundColumn DataField="sPhone"
    FilterControlAltText="Filter sPhone column" HeaderText="sPhone"
    SortExpression="sPhone" UniqueName="sPhone">
</telerik:GridBoundColumn>
<telerik:GridMaskedColumn DataField="sPhone" DisplayMask="(###) ###-####"
    FilterControlAltText="Filter column column" Mask="(###) ###-####" HeaderText="test"
    UniqueName="column">
</telerik:GridMaskedColumn>

The demo uses the Northwind db which has the phone number stored as a string as does my database.  Yet the mask doesn't take effect in my test.
0
Eyup
Telerik team
answered on 04 Mar 2013, 11:37 AM
Hello Neil,

The GridMaskedColumn generates a RadMaskedTextBox control for its edit mode, however, it does not modify the column content on view mode:
http://www.telerik.com/help/aspnet-ajax/grid-column-types.html

Also, please note that you can use this specific # DataFormatString with numeric values only:
http://msdn.microsoft.com/en-us/library/0c899ak8.aspx

For a string type field, you can use the following approach:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
    if (e.Item is GridDataItem)
    {
        GridDataItem dataItem = e.Item as GridDataItem;
        RadMaskedTextBox maskedBox = new RadMaskedTextBox();
 
        maskedBox.Mask = "(aaa) aaa-aaaa aaa";
        maskedBox.Text = dataItem["ColumnUniqueName"].Text;
 
        dataItem["ColumnUniqueName"].Text = maskedBox.TextWithLiterals;
    }
}

Hope this helps. Please give it a try and let me know if it works for you.

Kind regards,
Eyup
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
Grid
Asked by
Neil N
Top achievements
Rank 1
Veteran
Iron
Answers by
Princy
Top achievements
Rank 1
Neil N
Top achievements
Rank 1
Veteran
Iron
Eyup
Telerik team
Share this question
or