16 April 2007

DropDown navigation menu


The code for aspx page

<%@ Page Language="VB" %>
<script runat="server">
Protected Sub SelectionDropDownList_SelectedIndexChanged(ByVal sender As Object,
ByVal e As System.EventArgs) _
Handles SelectionDropDownList.SelectedIndexChanged

If Not (SelectionDropDownList.SelectedIndex = 0) Then

Page.Response.Redirect(Me.SelectionDropDownList.SelectedItem.Value)

End If
End Sub
</script>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:DropDownList ID="SelectionDropDownList" runat="server" AutoPostBack="True">
<asp:ListItem Selected="True">--Select Options--</asp:ListItem>
<asp:ListItem Value="http://www.sitepoint.com">Site point</asp:ListItem>
<asp:ListItem Value="http://www.google.com">Google</asp:ListItem>
<asp:ListItem Value="http://www.yahoo.com">Yahoo</asp:ListItem>
<asp:ListItem Value="http://www.live.com">Live Search</asp:ListItem>
</asp:DropDownList>
</div>
</form>
</body>
</html>


The HTML page

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>New Page 1</title>
<script type="text/javascript">
<!--
function NavigateUp(/*As String*/ elementID)
{
var theSelector = document.getElementById(elementID);
var theIndex = theSelector.selectedIndex;
var theUrl = theSelector.options[theIndex].value;

window.location.href = theUrl;

return true;
}
//-->
</script>
</head>

<body>
<select SelectedIndex="0" id="SelectionDropDownList"
onchange="NavigateUp(this.id);">
<option value="#">--Select Options--</option>
<option value="http://www.sitepoint.com">Site point</option>
<option value="http://www.google.com">Google</option>
<option value="http://www.yahoo.com">Yahoo</option>
<option value="http://www.live.com">Live Search</option>

</select>
</body>
</html>

No comments: