Solved

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

Posted on 2008-10-24
3
1,148 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
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…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

707 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

18 Experts available now in Live!

Get 1:1 Help Now