Hi Jeff,
There are a couple of ways to handle this, depending on whether you've
stored the phone numbers as numbers or as strings.
If they are numbers, you can format them quite readily. If they are strings,
you can convert the string to a number and then do the formatting. (That
seems like a hack but it works.)
Here's some demo code (below) that shows the various techniques including a
helper function. Let us know if it helps?
Ken
Microsoft MVP [ASP.NET]
Toronto
<asp:datagrid id="DataGrid1" runat="server"
AutoGenerateColumns="False">
<columns>
<asp:templatecolumn>
<itemtemplate>
<asp:Label runat="server" Text='<%#
DataBinder.Eval(Container, "DataItem.phone", "{0:###-###-####}") %>'>
</asp:label>
</itemtemplate>
</asp:templatecolumn>
<asp:boundcolumn DataField="phone" ReadOnly="True"
DataFormatString="{0:###-###-####}"></asp:boundcolumn>
<asp:templatecolumn>
<itemtemplate>
<asp:Label runat="server" Text='<%#
FixPhone(DataBinder.Eval(Container, "DataItem.phone")) %>'>
</asp:label>
</itemtemplate>
</asp:templatecolumn>
</columns>
</asp:datagrid>
Private Sub Page_Load _
(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
If Not IsPostBack Then
DataGrid1.DataSource = CreateDataSource()
DataGrid1.DataBind()
End If
End Sub
Public Function FixPhone _
(ByVal strNumber As String) As String
Dim mynum As String
mynum = "5551234567"
Return Format(Convert.ToDouble(mynum), _
"(###) ###-####")
End Function
Function CreateDataSource() As DataTable
Dim dt As New DataTable
Dim dr As DataRow
dt.Columns.Add(New DataColumn _
("ADateTime", GetType(DateTime)))
dt.Columns.Add(New DataColumn _
("phone", GetType(Long)))
dt.Columns.Add(New DataColumn _
("StringValue", GetType(String)))
dt.Columns.Add(New DataColumn _
("CurrencyValue", GetType(Double)))
dt.Columns.Add(New DataColumn _
("Boolean", GetType(Boolean)))
Dim i As Integer
For i = 0 To 8
dr = dt.NewRow()
dr(0) = Now.Date.AddDays(i)
dr(1) = 4165551210 + i
dr(2) = "Item " + i.ToString()
dr(3) = 1.23 * (i + 1)
dr(4) = (i = 4)
dt.Rows.Add(dr)
Next i
Return dt
End Function