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

Format Phone Number in the GridButtonColumn

2 Answers 160 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Asif
Top achievements
Rank 1
Asif asked on 15 Sep 2010, 01:14 PM
Hi,
               I have used the DataTextFormatString="{0:(###) ###-####}" to format the phone number in the GridButtonColumn which is not working. Please find the solution to format the phone in the GridButtonColumn in the Grid.
Note: Im using the Classic RadGrid.

Thanks in advance....

Best Regards,
Asif

2 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 16 Sep 2010, 07:55 AM
Hello Asif,

The DataTextFormatString property for phone number will only works if your data type in that column is of type numeric. I think you have stored the phone number as 'string'. So in ItemDataBound event, you can convert the data type of that column to something that can be formatted using the format string. Sample code is given below for your reference.

ASPX:
<telerik:GridButtonColumn DataTextField="phone" UniqueName="GridButtonColumn" HeaderText="GridButtonColumn" ></telerik:GridButtonColumn>

C#:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
    {
        if (e.Item is GridDataItem)
        {
            GridDataItem item = (GridDataItem)e.Item;
            LinkButton btn = (LinkButton)item["GridButtonColumn"].Controls[0];
            Object ob = btn.Text;
            if (!Convert.IsDBNull(ob))
            {
                Int64 iParsedValue = 0;
                if (Int64.TryParse(ob.ToString(), out iParsedValue))
                {
                    btn.Text = String.Format(System.Globalization.CultureInfo.CurrentCulture,
                       "{0:(###) ###-####}", new object[] { iParsedValue });
                }
            }
        }
    }

Thanks,
Princy.
0
Asif
Top achievements
Rank 1
answered on 16 Sep 2010, 11:17 AM
Its working fine..... thanks princy

Regards,
Asif
Tags
Grid
Asked by
Asif
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Asif
Top achievements
Rank 1
Share this question
or