Solved

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

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

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…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

840 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