james henderson
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?
Did you try using String.Format?
String.Format("{0:###-###- ####}",myp hone);
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.
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 >
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
ASKER
the problem is that the field, when updated, adds the mask to the database. How would I "unmask" the data?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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.
when updating the data, the phone number (or other masked input field) has to be un-masked prior to saving it to the database.