hyperlinks as part of dropdownlist

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Just wondering if there is a way to set up hyperlinks in a drop down list, so each item in the dropdown list navigates to a different page.
 
I don't know whether you want an immediate redirect to a page once user
selects an item from the drop down box or simply presents a URL for user to
go to.

Either way, you simply make sure to set the drop down box to autopostback.
If it's the former you require, simply call redirect method in the event
handler of the selectedindex_changed method of the drop down box. If the
latter, you need to have a second control (easiest being a hyperlink object
on the same web form) and set its navigateurl in the event handler of the
drop down box.

HTT
Paul said:
Just wondering if there is a way to set up hyperlinks in a drop down list,
so each item in the dropdown list navigates to a different page.
 
You can't exactly put hyperlinks in the list, but you could redirect
to a URL depending on what item the user has select in the control.

For example, if the following was in a web form:

<asp:DropDownList id="DropDownList1" runat="server">
<asp:ListItem Value="http://msdn.microsoft.com"
Selected="True">MSDN
</asp:ListItem>
<asp:ListItem Value="http://www.asp.net">ASP.Net
</asp:ListItem>
<asp:ListItem Value="http://www.google.com">Google
</asp:ListItem>
</asp:DropDownList>
<asp:Button id="Button1" runat="server" Text="Go"/>


Then you could add an event handler for the button click event and do
the following:

private void Button1_Click(object sender, System.EventArgs e)
{
Response.Redirect(DropDownList1.SelectedValue);
}

HTH,
 
Hi thanks for the response. I need to open a new window based on the selection, so may use window.open with some conditional code in the dropdown list change event.
 
Back
Top