Formatting phone number of a DetailsView control

  • Thread starter Thread starter womblesjc
  • Start date Start date
W

womblesjc

I have a data bound Details View control in asp.net 2.0 that formats a
phone number. The 'Default Mode' for the control is set to Edit. The
phone number field is a template field and I can successfully call a
function that formats the phone number when the control is filled. But
when updating, the value being passed in to my format function is
vbNull instead of the value in the phone number field of the control.
How can I get the update value to be the value of the phone number
field?
Here is the template field and formatting function. Thank You

<asp:TemplateField HeaderText="AltPhone" SortExpression="AltPhone"
ConvertEmptyStringToNull="False">
<EditItemTemplate>
<asp:TextBox ID="TextBox4" runat="server" MaxLength="14"
Text='<%# FormatPhoneNumber(DataBinder.Eval(Container.DataItem,
"AltPhone")) %>'></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>

Public Function FormatPhoneNumber(ByVal strNumber As String) As String
Dim strTemp as String = strNumber

If strTemp.Length > 0 Then
strTemp = strTemp.Replace("(", "")
strTemp = strTemp.Replace(")", "")
strTemp = strTemp.Replace("-", "")
End If

Return strTemp
End Function
 
have you tried using a RegularExpressionValidator control to simply force the
user to enter the phone number in the required format. If you are not good
with regular expresions then there is a nice library at www.regexlib.com.
 
Back
Top