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
0

Princy
Top achievements
Rank 2
answered on 28 Feb 2013, 07:38 AM
Hi,
One suggestion is that you can use a MaskedColumn as shown below.
aspx:
Thanks,
Princy
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 2
Iron
Iron
Veteran
answered on 02 Mar 2013, 11:40 PM
Weird. Following up on your suggestion I looked at the online demo for
My test code:
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.
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
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:
Hope this helps. Please give it a try and let me know if it works for you.
Kind regards,
Eyup
the Telerik team
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.