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?
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Did you try using String.Format?
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
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

C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

dhenderson12Author Commented:
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
dhenderson12Author Commented:
the problem is that the field, when updated, adds the mask to the database.  How would I "unmask" the data?
Can you explain more on "adds the mask to the database.  How would I "unmask" the data? "?

If I am understanding it correct then you can write a custom function and pass it the masked data, and strip the unwanted symbols before saving it.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
dhenderson12Author Commented:
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.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.