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

[Solved] DataFormatString is not applied

4 Answers 146 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Chetan
Top achievements
Rank 1
Chetan asked on 04 Apr 2013, 11:42 AM
I have a radgrid and it has dynamically added columns using following code. I have phone number column and I want to apply dataformatstring for this column but it is not getting reflected. What is that I am missing here?

GridBoundColumn boundColumn1 = new GridBoundColumn();
RadGrid1.MasterTableView.Columns.Add(boundColumn1);
boundColumn1.ItemStyle.Wrap = false;
boundColumn1.DataField = "PhoneNumber";
boundColumn1.UniqueName = "PhoneNumber";
boundColumn1.SortExpression = "PhoneNumber";
boundColumn1.HeaderText = "Phone Number";
boundColumn1.AllowFiltering = AllowFiltering;
boundColumn1.ShowFilterIcon = false;
boundColumn1.AutoPostBackOnFilter = true;
boundColumn1.DataFormatString = "{0:(###)###-###}";

Please help

Thank you

4 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 04 Apr 2013, 12:08 PM
Hi,

In order string format to be applied the data should be of the correct type. Thus in the your case the data should be of some numeric type (int, double, float etc) , please specify data type.
C#:
boundColumn1.DataType = Type.GetType("System.Double");

Thanks,
Shinu
0
Chetan
Top achievements
Rank 1
answered on 04 Apr 2013, 12:12 PM
What if there are phone numbers like UI12312312? Also I tried but it is not working there.
boundColumn1.DataType = Type.GetType("System.Double");
0
Chetan
Top achievements
Rank 1
answered on 05 Apr 2013, 05:45 AM
Is there any solution for this?
0
Andrey
Telerik team
answered on 09 Apr 2013, 07:02 AM
Hello,

It is better to use the GridMaskedColumn for this purpose instead of the GridBoundColumn. You could check this online demo application which demonstrates the approach.

Kind regards,
Andrey
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
Chetan
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Chetan
Top achievements
Rank 1
Andrey
Telerik team
Share this question
or