-
Oct 30th, 2008, 08:56 AM
#1
Thread Starter
Frenzied Member
[RESOLVED] [02/03] Format Phone number in Datagrid BoundField
How do you format a cell to display 999-999-9999 in a Datagrid in VS2003? There is no htmlencode property of the field...
thanks.
-
Oct 30th, 2008, 12:58 PM
#2
Thread Starter
Frenzied Member
Re: [RESOLVED] [02/03] Format Phone number in Datagrid BoundField
Just made a function to handle the string manipulation...
-
Oct 31st, 2008, 10:04 AM
#3
Re: [RESOLVED] [02/03] Format Phone number in Datagrid BoundField
Share your solution with the world.
-
Oct 31st, 2008, 10:12 AM
#4
Thread Starter
Frenzied Member
Re: [RESOLVED] [02/03] Format Phone number in Datagrid BoundField
Sorry was a quick solution so I'm sure it could be written better:
vb Code:
Public Function convertPhone(ByVal stNumber As Object) As String
Dim newString As String
Try
newString = Mid(stNumber.ToString, 1, 3) & "-"
newString = newString & Mid(stNumber.ToString, 3, 3) & "-"
newString = newString & Mid(stNumber.ToString, 6, 4)
If newString = "--" Then
newString = ""
End If
Catch ex As Exception
End Try
Return newString
End Function
Code:
<asp:TemplateColumn HeaderText="Phone">
<HeaderStyle Width="100px"></HeaderStyle>
<ItemTemplate>
<%# convertPhone(DataBinder.Eval(Container.DataItem, "srs_Contact_Phone")) %>
</ItemTemplate>
</asp:TemplateColumn>
-
Oct 31st, 2008, 10:56 AM
#5
Re: [RESOLVED] [02/03] Format Phone number in Datagrid BoundField
Oh, I think you could have done this using String.Format in the codebehind, or using the DataFormatString property of the column (bound column only) with something like {0:###-###-####} in it.
-
Oct 31st, 2008, 11:50 AM
#6
Thread Starter
Frenzied Member
Re: [RESOLVED] [02/03] Format Phone number in Datagrid BoundField
Yeah the string.format in code behind probably works. I did try the DataStringFormat on a bound field but there weren't any results so I was thinking it was due to not haveing the HTMLEncode property.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|