By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,866 Members | 1,660 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,866 IT Pros & Developers. It's quick & easy.

Formatting phone number of a DetailsView control

P: n/a
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.DataIt em,
"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

Mar 22 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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.

"wo*******@royell.org" wrote:
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.DataIt em,
"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

Mar 22 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.