listbox - jump to URL

Hi Experts

New to ASP.NET2 so forgive a silly question.

I have a listbox control, databound to an underlying class for its data. What I want to do is open  link based on the ID of the item in the list box.

Google dosn't have the answer.

Andy GreenAsked:
Who is Participating?
Dustin HopkinsConnect With a Mentor Senior Web DeveloperCommented:
So you want to pass the selectedvalue to another page as a param, instead of the selectedvalue being the page you wanted to redirect to?

You could use session variables. For those you need to have something like the following in the code behimd for your dropdown.
Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged
        Dim value_to_pass As String = DropDownList1.SelectedValue  <---This get the value form the ddl
        Session.Add("passed_value", value_to_pass) <---This stores it to the session state
        Response.Redirect("~/floatdetail.aspx", True) <---this transfers your page
    End Sub
Then on the detail page you could pull the variable back out like this to use it anywhere on the page:
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim passed_variable As String = Session.Contents("passed_value")
    End Sub
or if its for a datasource then you can use the following in the select parameters:
       <asp:sessionparameter DefaultValue="" Name="param name in query"
           SessionField="passed_value" Type="Int32" />

Hope this helps...
on what event when someone clicks on a button?

You can get the selectedValue using ListboxName.SelectedValue

eg response.redirect(ListBox1.selectedValue)
Andy GreenAuthor Commented:

Yes I can capture that event, but how do I then jump to a URL. I guess I can append the selected index to the querystring, or is there another way in

Dustin HopkinsSenior Web DeveloperCommented:
That is an example for a dropdown, but a listbox should work the same way.
Andy GreenAuthor Commented:
Thanks Dusion,

I'd already figure the dropdown / listbox thing.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.