Solved listbox - jump to URL

Posted on 2007-10-05
Last Modified: 2008-01-09
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.

Question by:Andy Green
    LVL 7

    Expert Comment

    on what event when someone clicks on a button?

    You can get the selectedValue using ListboxName.SelectedValue

    eg response.redirect(ListBox1.selectedValue)
    LVL 3

    Author Comment

    by:Andy Green

    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

    LVL 14

    Accepted Solution

    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...
    LVL 14

    Expert Comment

    by:Dustin Hopkins
    That is an example for a dropdown, but a listbox should work the same way.
    LVL 3

    Author Comment

    by:Andy Green
    Thanks Dusion,

    I'd already figure the dropdown / listbox thing.


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
    ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.

    758 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now