ASP.net 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
LVL 3
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:
<SelectParameters>
       <asp:sessionparameter DefaultValue="" Name="param name in query"
           SessionField="passed_value" Type="Int32" />
   </SelectParameters>

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

You can get the selectedValue using ListboxName.SelectedValue

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

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 ASP.net.

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

I'd already figure the dropdown / listbox thing.

ANdy
0
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.