[RESOLVED] [02/03] Format Phone number in Datagrid BoundField-VBForums
Results 1 to 6 of 6

Thread: [RESOLVED] [02/03] Format Phone number in Datagrid BoundField

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2001
    Location
    Mass USA
    Posts
    1,674

    Resolved [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.

  2. #2

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2001
    Location
    Mass USA
    Posts
    1,674

    Re: [RESOLVED] [02/03] Format Phone number in Datagrid BoundField

    Just made a function to handle the string manipulation...

  3. #3
    ASP.NET Moderator mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,174

    Re: [RESOLVED] [02/03] Format Phone number in Datagrid BoundField

    Share your solution with the world.

  4. #4

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2001
    Location
    Mass USA
    Posts
    1,674

    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:
    1. Public Function convertPhone(ByVal stNumber As Object) As String
    2.         Dim newString As String
    3.         Try
    4.             newString = Mid(stNumber.ToString, 1, 3) & "-"
    5.             newString = newString & Mid(stNumber.ToString, 3, 3) & "-"
    6.             newString = newString & Mid(stNumber.ToString, 6, 4)
    7.             If newString = "--" Then
    8.                 newString = ""
    9.             End If
    10.         Catch ex As Exception
    11.  
    12.         End Try
    13.         Return newString
    14.     End Function

    Code:
    					<asp:TemplateColumn HeaderText="Phone">
    						<HeaderStyle Width="100px"></HeaderStyle>
    						<ItemTemplate>
    							<%# convertPhone(DataBinder.Eval(Container.DataItem, "srs_Contact_Phone")) %>
    						</ItemTemplate>
    					</asp:TemplateColumn>

  5. #5
    ASP.NET Moderator mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,174

    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.

  6. #6

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2001
    Location
    Mass USA
    Posts
    1,674

    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
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.