Masking DataTextField Output For Display In a ListBox

N

NBB

I can't figure this one out. Here's the situation, should be pretty
for the pros in here.

I have a ListBox that is populated with the DataTextField and
DataValueField flags of the DataSet. Everything populates just fine
and works great.

The DataTextField displays text from a database column called Path,
which is the absolute URL of a file. What I would like it to display
is just the filename, essentially trimming off everything previous to
(and including) the last forward slash character of the URL. I've come
up with this:

Right(thepath, (Len(thepath) - (thepath.LastIndexOf("/")+1)))

Where "thepath" is a string representing the absolute URL. It works
great when I manually define thepath as a string. But I don't have
any idea how to implement this on the the values coming out of the
database's Path column.

I've been playing with the OnDataBinding and OnPreRender events for 2
days, but, alas, can't get them to work with the output of the
DataTextField.

Could someone shed some light on the matter? I doesn't seem like it
should be that hard to use a replace function or something like my
masking technique on the output, but I'm stumped.

Thanks for any help you can provide!


By the way, that's no longer my email address, so don't send to it.
I'll have to update my Google profile later today.
 
N

NBB

Just following up my previous post (below) in case anyone is looking
to do the same type of thing. I've finally figured it out and have it
working as follows.

After populating my listbox in the typical way, I created a new public
sub as follows:

====================================================
Public Sub Mask(Sender As Object, E As EventArgs)
Dim li As ListItem
For Each li In MyListBox.Items
li.text = Right(li.Text, (Len(li.Text) -
(li.text.LastIndexOf("/")+1)))
Next
End Sub
====================================================
Then, I added the event to the asp:listbox as:

OnPreRender="Mask"

The result of all this turns the contents of the database field:
"http://localhost/mysite/directory1/directory2/myfile.mp3" into
"myfile.mp3"

Much easier to fit in a 100px wide listbox. :)

I got this idea from researching a totally different issue here in the
groups nonetheless.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top