adding links to a listbox [RESOLVED]
I have a program that searches a text file for a particular string and pulls some information to display in a listbox. That information can be used to build a url that I want to display in the listbox.
This is kind of what I want to do:
VB Code:
For Each dElement As String In dArray
link = "<a href=" + Chr(34) + "http://www.company.com/info.asp?info=" + dElement + Chr(34) + ">" + dElement + "</a>"
ListBox1.Items.Add(link)
Next
but it ends up just showing:
Quote:
<a href="http://www.company.com/info.asp?info=1234">1234</a>
rather than have "1234" be a link.
I've looked at the link class, but when I try to do the "Imports System.Web.UI.MobileControls" the intellisense doesn't know what that is.
Any ideas on what I'm doing wrong?
Re: adding links to a listbox
if you want to import System.Web.UI.MobileControls you have to make a reference to the web.dll in your project
Re: adding links to a listbox
Windows form example. It can be easly modified for web site.
...
' Windows Form Designer generated code
Dim ok As New SortedList
Dim okk As DictionaryEntry
Private Sub Form6_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
ok.Add("Link 1", "http://www.vbfan.com")
ok.Add("Link 2", "http://www.microsoft.com")
For Each okk In ok
Me.ListBox1.Items.Add(okk.Key)
Next
End Sub
Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
Process.Start(okk.Value)
End Sub
-------------------------------------------------------------------
Now, all you have to do is fill values from your text file.
Re: adding links to a listbox
vbdotnetboy, as per usual, that thought hit me 3 minutes after I hit the post button.
So now I have:
VB Code:
For Each da As String In DArray
defLink.Text = da
defLink.NavigateUrl = "http://www.company.com/infolog.asp?info=" + da
ListBox1.Items.Add(defLink)
Next
Stepping through the code, the attributes get populated correctly, but the listbox displays "System.Web.UI.MobileControls.Link".
Hmmm... VBnetFan at first I didn't think your idea applied, but now I have an idea. Say that DArray is already sorted and I do:
VB Code:
For Each da As String In DArray
ListBox1.Items.Add(da)
Next
This populates the listbox. Then I could get the selectedindexchanged event to trigger it like this:
VB Code:
Private Sub ListBox1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
Process.Start("http://www.company.com/infolog.asp?info=" + sender.text)
End Sub
The problem is getting the text of the selected index. Any idea on how to do that?
Re: adding links to a listbox
Got it, "ListBox1.SelectedItem", Duh!
VB Code:
Private Sub ListBox1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
Process.Start("http://www.company.com/infolog.asp?info=" + ListBox1.SelectedItem)
End Sub
Thanks guys.
Re: adding links to a listbox [RESOLVED]
just for the record... this is a windows app right??? I think everyone who posted thinks its an ASP.NET app
Re: adding links to a listbox [RESOLVED]
what is asp.NET ??? :sick: