Dropdownlist navigation

The dropdownlist displays 3 URLs that the visitor can choose from. Once a URL has been selected the visitor is automatically redirected to that website. Our Dropdownlist has it's autopostback property set to true, so once the SelectedIndexChanged event has been raised the page is posted back to the server and the associated subroutine DropDownList1_SelectedIndexChanged is executed. The subroutine gets the value from the selected item property and does a redirect to the URL.

The subroutine will only be run if the selection changes, as our default ListItem is 'SELECT A URL' we need to select another ListItem to trigger the SelectedIndexChanged event.

<%@ Page Language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs)
    Response.Redirect(DropDownList1.SelectedItem.Value)
End Sub

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Dropdownlist Navigation</title>
</head>
<body>
<form id="form1" runat="server">

<div>

<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
<asp:ListItem Selected="True">SELECT A URL</asp:ListItem>
<asp:ListItem Value="http://www.codefixer.com">Codefixer</asp:ListItem>
<asp:ListItem Value="http://www.w3schools.com">W3Schools</asp:ListItem>
<asp:ListItem Value="http://www.asp101.com">ASP101</asp:ListItem>
</asp:DropDownList>

</div>

</form>
</body>
</html>

Get the best asp web hosting provider now and save 30%

Advertisements



MembersPro

MembersPro PayPal - ASP Membership software

Plug and play ASP membership script that integrates with PayPal to let you charge recurring membership fees.