• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 252
  • Last Modified:

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
0
Andy Green
Asked:
Andy Green
  • 2
  • 2
1 Solution
 
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 HopkinsCommented:
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
 
Dustin HopkinsCommented:
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

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now