Solved

Hyperlink in dropdown list so when a selection is made redirects to that page

Posted on 2008-10-24
3
1,152 Views
Last Modified: 2012-05-05
I have a web site done in ASP.NET with VB.NET.  I have to add a dropdownlist that has hyperlinks so when somone selects an item from the list they are redirected to that URL.  I have the following, but it's taking me anywhere.  What am I doing wrong?

<asp:DropDownList id="ddlDropDown1" SelectedIndexChanged="RedirectMe" runat="server">
                  <asp:ListItem Value="product_list.aspx?id=8">Allergy Relief</asp:ListItem>
                  <asp:ListItem Value="product_list.aspx?id=11">Arthritis</asp:ListItem>
                  </asp:DropDownList>

Sub RedirectMe(ByVal s As Object, ByVal e As EventArgs)
        Dim RedirectUrl As String = ddlDropDown1.SelectedValue
        Response.Redirect(RedirectUrl)
    End Sub
0
Comment
Question by:OVC-it-guy
  • 2
3 Comments
 
LVL 3

Accepted Solution

by:
ahll earned 500 total points
ID: 22800295
Hi
Try this code

Just make sure of having set the AutoPostback for the DDL.

Hope it helps
aspx page
 
    <asp:DropDownList
        ID="DropDownList1" runat="server" AutoPostBack="True" 
            onselectedindexchanged="DropDownList1_SelectedIndexChanged">
        <asp:ListItem Value="mypage.aspx?id=1">First Choice</asp:ListItem>
        <asp:ListItem Value="mypage.aspx?id=2">Second Choice</asp:ListItem>
    </asp:DropDownList>
 
 
aspx.cs page
 
        protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
        {
            Response.Redirect(DropDownList1.SelectedValue.ToString());
        }

Open in new window

0
 

Author Comment

by:OVC-it-guy
ID: 22800510
Can I get that in VB.NET, since the rest of the page is?
0
 

Author Closing Comment

by:OVC-it-guy
ID: 31509833
Thank you anyway.  I got the VB.NET myself.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

726 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