•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the ASP.NET section within the Web Development category of DaniWeb, a massive community of 392,007 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 4,187 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our ASP.NET advertiser: Lunarpages ASP Web Hosting
Views: 21264 | Replies: 7 | Solved
![]() |
•
•
•
•
Originally Posted by slade
Hi, I need to know how I would go about making a drop down menu in asp .net using vb .net...
Thanks,
Slade
Hope this helps dude!
//**************************************
// Name: Menu pagelet for ASP.NET
// Description:Simple server-side menu control - kind of - for ASP.NET pages. It's best suited for a site where all pages use the same menu. All pages share the same pagelet, which contains all the menu items and the logic. You can define two menu levels (main menu and submenus). When you click on a main menu item the submenu drops down. The currently shown page is shown bold in the menu.
The code contains the pagelet (navbar.ascx) and a sample page using it.
// By: Klemens Schmid (old)
//
//
// Inputs:None
//
// Returns:None
//
//Assumes:The code uses VB.NET syntax but almost no dotnet features. You could adapt the code to work under plain ASP as well. The pagelet would become an include then. However, this is less elegant then using pagelets in ASP.NET.
You can see the code in action at www.klemid.de/aspmenu.aspx.
Maybe you need my styles.css to make it look good.
//
//Side Effects:None
//This code is copyrighted and has limited warranties.
//Please see http://www.Planet-Source-Code.com/xq...s/ShowCode.htm
//for details.
//**************************************
--------------------------------------------------
Pagelet code:
--------------------------------------------------
<!-- navigation bar for klemid's web
<script language="VB" runat="server">
Dim MenuEntry(,) As object = { _
{"Home", "welcome.aspx", "", true}, _
{"Interests", "interests.aspx", "", true}, _
{"My Tools", "tools.aspx", "", true}, _
{"ASP.NET Menu", "aspmenu.aspx", "My Tools", false}, _
{"SMS via http", "vbsms.aspx", "My Tools", false}, _
{"OL2WAP", "ol2wap.aspx", "My Tools", false}, _
{"Form Sniffer", "formsniffer2.aspx", "My Tools", false}, _
{"Crypt File", "cryptfile.aspx", "My Tools", false}, _
{"Copy Contacts", "copycontacts.aspx", "My Tools", false}, _
{"eBay Reminder", "ebayrem.aspx", "My Tools", false}, _
{"Fav2Web", "fav2web.aspx", "My Tools", false}, _
{"Lex4VB", "lex4vb.aspx", "My Tools", false}, _
{"M-Pad", "mpad.asp", "", true}, _
{"My Charts", "mycharts.aspx", "", true}, _
{"Select", "mycharts1.aspx", "My Charts", false}, _
{"Display", "mycharts2.aspx", "My Charts", false}, _
{"Urlaub", "urlaub.aspx", "", true}, _
{"Ruhpolding", "ruhpolding.aspx", "Urlaub", false}, _
{"Wiesloch", "wiesloch.aspx", "", true}, _
{"Top 30 WapMarks", "topwap.aspx", "", true}, _
{"Top 30 WebMarks", "topweb.aspx", "", true}, _
{"All My WebMarks", "allweb.aspx", "", true}, _
{"", "", "", true}, _
{"Email", "mailto:feedback@schmidks.de?subject=Feedback", "", true}, _
{"Disclaimer", "http://www.disclaimer.de/disclaimer.htm", "", true} _
}
Dim i as integer
Dim strCurrentPage as String
dim bSubmenuStarting as Boolean = false
Sub Page_Load(Source as Object, E as EventArgs)
Dim i, j as Integer
Dim strParent as String
'switch on the submenu according to the currently displayed page
strCurrentPage = Request.Url.Segments.GetValue(Request.Url.Segments.GetUpperBound(0))
For i=0 To MenuEntry.GetUpperBound(0)
If MenuEntry(i, 1) = strCurrentPage Then
If MenuEntry(i, 2) = "" Then
'main menu item was clicked
strParent = MenuEntry(i, 0)
Else
'submenu item was clicked
strParent = MenuEntry(i,2)
End If
'found -> switch on the 'visible' flag for submenu items
For j=0 To MenuEntry.GetUpperBound(0)
If MenuEntry(j, 2) = strParent Then
MenuEntry(j, 3) = True
End If
Next
Exit For
End If
Next
End Sub
</script>
-->
<table cellspacing="1" cellpadding="3" bgcolor="white" align=center>
<% for i=0 to MenuEntry.GetUpperBound(0) %>
<% if MenuEntry(i,0) = "" Then 'separator line%>
<tr>
<td bgcolor="#dedebe" height="1">
</tr>
<tr>
<td bgcolor="#dedebe" height="1">
</tr>
<% else 'normal link %>
<% if i > 0 AndAlso MenuEntry(i-1, 2) <> "" AndAlso MenuEntry(i, 2) = "" AndAlso MenuEntry(i-1, 3) Then 'submenu ends %>
</table>
<% end if %>
<% bSubmenuStarting = (i > 0 AndAlso MenuEntry(i, 2) <> "" AndAlso MenuEntry(i, 3) AndAlso MenuEntry(i+1, 2) = "") %>
<% if bSubmenuStarting Then %>
<td bgcolor="#f2f2e6" >
<table border="0" cellspacing="0" bgcolor="#ececd9">
<% end if %>
<% if MenuEntry(i, 2) <> "" Then 'submenu entry %>
<% if MenuEntry(i, 3) Then %>
<tr>
<td width="100%" bgcolor="#f2f2e6" <%= IIf(MenuEntry(i,1)=strCurrentPage, "style=""FONT-WEIGHT: bold""", "") %> >
<font size="2"><nobr>
<a href="<%= MenuEntry(i,1) %>" class="NavLink"><%= MenuEntry(i,0)%></a>
</nobr></font>
</td>
</tr>
<% End if%>
<% else 'main menu %>
<tr>
<td bgcolor="#dedebe" height="18" <%= IIf(MenuEntry(i,1)=strCurrentPage, "style=""FONT-WEIGHT: bold""", "") %> >
<nobr>
<a href="<%= MenuEntry(i,1) %>" class="NavLink"><%= MenuEntry(i,0)%></a>
</nobr>
</td>
</tr>
<% end if %>
<% end if %>
<% next %>
</table>
--------------------------------------------------
Sample page
--------------------------------------------------
<%@ Register TagPrefix="klemid" TagName="NavBar" Src="navbar.ascx" %>
<%@ Page Language="vb" AutoEventWireup="true" Debug="true" %>
<%@ Import namespace="System.IO" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>ASP.NET Menu</title>
<meta content="Microsoft Visual Studio.NET 7.0" name="GENERATOR">
<meta content="Visual Basic 7.0" name="CODE_LANGUAGE">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<meta http-equiv="Content-Language" content="en-us">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
<LINK href="Styles.css" type="text/css" rel="stylesheet">
<script id="fill" runat="server">
Sub Page_Load(sender as object, e as System.EventArgs)
Dim SReadToEnd As Stream
'read the pagelet
SReadToEnd = File.OpenRead(Page.MapPath(".\navbar.ascx"))
Dim SrReadToEnd As StreamReader = New StreamReader(SReadToEnd, _
System.Text.Encoding.ASCII)
'SrReadToEnd.BaseStream.Seek(0, SeekOrigin.Begin)
txtPagelet.Text = SrReadToEnd.ReadToEnd()
SrReadToEnd.Close()
'read this page
SReadToEnd = File.OpenRead(Page.MapPath(Page.Request.FilePath()))
SrReadToEnd = New StreamReader(SReadToEnd, System.Text.Encoding.ASCII)
'SrReadToEnd.BaseStream.Seek(0, SeekOrigin.Begin)
txtThisPage.Text = SrReadToEnd.ReadToEnd()
SrReadToEnd.Close()
End Sub
</script>
</HEAD>
<body style="BACKGROUND-IMAGE: none" leftMargin="0" topMargin="0" marginheight="0" marginwidth="0">
<table dir="ltr" height="100%" cellSpacing="0" cellPadding="10" width="100%" border="0">
<tr>
<td vAlign="top" bgColor="#cccc99">
<!-- header --><klemid:navbar id="NavBar" runat="server"></klemid:navbar></td>
<td vAlign="top" width="100%">
<!-- actual body goes here --><a name="Oben"></a>
<h2 align="center">ASP.NET Menu</h2>
<p>
<p style="MARGIN-TOP: 10px; MARGIN-BOTTOM: 5px" align="center">
Inspect the source code of the menu seen on the left side
<P>
<P>
<hr>
See how the menu on the left side of my pages is implemented. It is done by an
ASP.NET pagelet. Of course, you can buy a full-blown ASP.NET menu control like
the ones found at <A href="http://www.asp.net">www.asp.net</A>
, but those are not free and they are mostly overkill for a small web site
having only one menu.
<P></P>
<P>Although the code here works only for ASP.NET it would be an easy exercise the
adapt it for pure ASP.
</P>
<form runat="server">
<P></P>
<P>Pagelet code (navbar.ascx):</P>
<P>
<asp:TextBox id="txtPagelet" runat="server" Width="100%" Height="114px" TextMode="MultiLine" ReadOnly="True"></asp:TextBox></P>
<P>This page's code:</P>
<p></p>
<asp:TextBox id="txtThisPage" runat="server" Width="100%" Height="114px" TextMode="MultiLine" DESIGNTIMEDRAGDROP="282" ReadOnly="True"></asp:TextBox>
<P></P>
<P> </P>
</form>
</td>
</tr>
</table>
</body>
</HTML>Now this is not really a drop down menu, but it is a Side Panel Menu similar to MS Access Database window or the side panel menu's in Windows XP.
I am sure I have source code at home to do exactly what you want, but I could be wrong. It may be source code to do it in JavaScript!
Later
Assistant Manager, Regional Pharmacy Information Systems
TLC Services Website (Under Construction)
Updated : ASP.Net Login Code
TLC Services Website (Under Construction)
Updated : ASP.Net Login Code
A better solution would be skmMenu, an open-source ASP.NET based menu application.
-Ryan Hoffman
ASP.NET Specialist / Webmaster, Extended64.com.
Please do not email or PM me with support questions. Please direct them to the forums instead.
ASP.NET Specialist / Webmaster, Extended64.com.
Please do not email or PM me with support questions. Please direct them to the forums instead.
Just doing what Dani forces me to ;-).
-Ryan Hoffman
ASP.NET Specialist / Webmaster, Extended64.com.
Please do not email or PM me with support questions. Please direct them to the forums instead.
ASP.NET Specialist / Webmaster, Extended64.com.
Please do not email or PM me with support questions. Please direct them to the forums instead.
Forces.....Forces...hmmm, why do I find that hard to believe? Although Dani being forceful does have some interesting connotations to it.
Assistant Manager, Regional Pharmacy Information Systems
TLC Services Website (Under Construction)
Updated : ASP.Net Login Code
TLC Services Website (Under Construction)
Updated : ASP.Net Login Code
•
•
•
•
Originally Posted by Paladine
Forces.....Forces...hmmm, why do I find that hard to believe? Although Dani being forceful does have some interesting connotations to it.
Well, heh ;-). This thread had my first post that I didn't type from Dani's house in about three weeks. She doesn't force me at gunpoint, but, she begs in a cute way, and ya just can't say no
. LOL -Ryan Hoffman
ASP.NET Specialist / Webmaster, Extended64.com.
Please do not email or PM me with support questions. Please direct them to the forums instead.
ASP.NET Specialist / Webmaster, Extended64.com.
Please do not email or PM me with support questions. Please direct them to the forums instead.

Hahaha.. LOL I had figured she had that way about her, that certain irresistable charm to do as she asks. :lol: :cheesy:
And we appreciate her doing so, your assistance is of course appreciated as well!
Assistant Manager, Regional Pharmacy Information Systems
TLC Services Website (Under Construction)
Updated : ASP.Net Login Code
TLC Services Website (Under Construction)
Updated : ASP.Net Login Code
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb ASP.NET Marketplace
- XP Startup Problem: Infinite Loop (Windows NT / 2000 / XP / 2003)
- opera problems with hover menu (JavaScript / DHTML / AJAX)
- defective 15-pin vga connector (Monitors, Displays and Video Cards)
- Cd Tary Wont Open (Storage)
- php + Javascript (PHP)
- daniweb on my start menu (Windows NT / 2000 / XP / 2003)
- For some reason program installations cannot create new start menu shortcuts... (Windows NT / 2000 / XP / 2003)
- IE6 has been constantly hijacked by .... (Viruses, Spyware and other Nasties)
Other Threads in the ASP.NET Forum
- Previous Thread: ASP .NET database hit counter
- Next Thread: Error with manifest resource files


Linear Mode