Link to home
Start Free TrialLog in
Avatar of james henderson
james hendersonFlag for United States of America

asked on

formatting data in detailsview

I have a detailsview control with itemtemplate, edittemplate, and inserttemplate.  One of the fields is a phone number that I would like to format to (xxx) xxx-xxxx.  How can I do this in the template fields for edit, insert, and readonly?
Avatar of YZlat
YZlat
Flag of United States of America image

Did you try using String.Format?
String.Format("{0:###-###-####}",myphone);
You can do it in several ways:

1: Handle the DataBound event format your data in there

2: You can call a function and pass the value to it and format it the way you want
e.g.
string FormattedPhone(object phone){
//format the phone as you like here and then return.
}

 <asp:TextBox ID="txtPhone" runat="server" Text='<%# FormattedPhone(Eval('Phone')) %>'></asp:TextBox >

Open in new window

Avatar of james henderson

ASKER

I should have been more clear.  I'm looking to do a "masked edit" sort of thing, so not only does it display, but the mask is intact during edit and/or insert, and the user types into the masked field.
You might want to check into jquery plugins. Sample
the problem is that the field, when updated, adds the mask to the database.  How would I "unmask" the data?
ASKER CERTIFIED SOLUTION
Avatar of guru_sami
guru_sami
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
yeah, I was being dumb.  use the jquery to provide a masked input and do the formatting in code-behind for display purposes.  

when  updating the data, the phone number (or other masked input field) has to be un-masked prior to saving it to the database.