473,396 Members | 2,158 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

format phone in a repeater/datalist

TJ
The phone number in my dataset is formatted 5558675309.
I present it in the aspx page as <%#
DataBinder.Eval(Container.DataItem,"phone_number") %>
How can I format this to show it like 555-867-5309?
I could do this in code behind no prob,but I'm pretty rough when it comes to
string formatting in the aspx page.

Nov 19 '05 #1
4 2221
Assuming you can count on the phone number being ten digits long, you
could do something like this:

'Inside the aspx page
<asp:TextBox id=txtPhone
Text='ReturnPhoneNumber(Container.DataItem("phone_ number")'
runat=server />

'Inside the code behind file
Protected Function ReturnPhone (Phone As String) As String
Return Phone.Substring(0, 3) & "-" & Phone.Substring(3, 3) & "-" &
Phone.Substring(6)
End Function

Hopefully there are no typos in that.

Scott

Nov 19 '05 #2
Oops, there was:

<asp:TextBox id=txtPhone
Text='ReturnPhoneNumber(Container.DataItem("phone_ number"))'
runat=server />

Nov 19 '05 #3
TJ
Thanks for the very fast response.

Hmm...the textbox displays not the formatted return string from the
function, but rather the exact text we put into the aspx page calling it,
"'ReturnPhoneNumber(Container.DataItem("phone_numb er"))". Hmmm.

This technique seems valid, thx for pointing me in the right direction. Hope
it doesn't matter that the code is actually in a nested repeater...but w/o
trying to format from a code behind function shows it just fine (just ugly
and unformatted).

<Sc***********@excite.com> wrote in message
news:11**********************@g43g2000cwa.googlegr oups.com...
Oops, there was:

<asp:TextBox id=txtPhone
Text='ReturnPhoneNumber(Container.DataItem("phone_ number"))'
runat=server />

Nov 19 '05 #4
Ah, because the delimiters were not put around the call to
ReturnPhoneNumber function:

<asp:TextBox id=txtPhone
Text='<%# ReturnPhoneNumber(Container.DataItem("phone_number ")) %>'
runat=server />

Nov 19 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Fredrik Rodin | last post by:
All, I'm looking for a way of generating a grouping in a repeater (or other control). Instaed of describing everything here, just look at this link and you can see how I did it in classic asp...
0
by: Shun Duke | last post by:
I have working code allowing me to nest repeaters inside datalists using relations and child rows but this does not allow me to acheive my goal. What I want to be able to do is display small...
1
by: Hans Merkl | last post by:
Hi, I must be missing something here. In a DataList and DataGrid I can use the property DataKeys to identify the selected element and get to its values. But I can't find a way to do the same in...
3
by: GD | last post by:
I'm using a DataList and a Repeater (nested in the DataList) to display a list of "Chapters" and "Documents" within the Chapters. <asp:DataList ID="dlChapter" Runat="server" RepeatColumns="2"...
7
by: Doug Parker | last post by:
I'm trying to use the repeater control to create a column-like row of data, I've searched the net and it doesn't appear to be that easy. Use this page for reference: ...
2
by: Steve | last post by:
I am having issues adding a new row in my repeater when my repeater's table cells reach a certain number. what i'm doing is adding a predetermined number of color cells from the database and...
0
by: warren_rapson | last post by:
Hi all, I am a newbie to this awesome framework - i love it. My situation: - I have a master page with a menu on it and a ContenPlaceHolder containing a DataList - The menu is dynamic and is...
2
by: mj.redfox.mj | last post by:
Hi, I wonder if someone could possibly help with this? I have the following code, which is a nested repeater in turn nesting a datalist. This all works fine, together with my page-behind vb code...
2
by: Paulo | last post by:
What is DetailsView, FormView, DataList, Repeater components? Any differences? VS 2005 asp.net C#
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.