By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,473 Members | 3,229 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,473 IT Pros & Developers. It's quick & easy.

Masking DataTextField Output For Display In a ListBox

P: n/a
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.
Nov 18 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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.

De********@earthlink.net (NBB) wrote in message news:<49**************************@posting.google. com>...
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.

Nov 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.