Drop Down Menu

Please support our ASP.NET advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Mar 2004
Posts: 634
Reputation: Slade has a spectacular aura about Slade has a spectacular aura about 
Solved Threads: 7
Slade's Avatar
Slade Slade is offline Offline
Practically a Master Poster

Drop Down Menu

 
0
  #1
Jun 29th, 2004
Hi, I need to know how I would go about making a drop down menu in asp .net using vb .net...

Thanks,

Slade
Formerly known as Slade.
Reply With Quote Quick reply to this message  
Join Date: Feb 2003
Posts: 793
Reputation: Paladine has a spectacular aura about Paladine has a spectacular aura about Paladine has a spectacular aura about 
Solved Threads: 26
Team Colleague
Paladine's Avatar
Paladine Paladine is offline Offline
Master Poster

Re: Drop Down Menu

 
0
  #2
Jul 3rd, 2004
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!

  1. //**************************************
  2. // Name: Menu pagelet for ASP.NET
  3. // 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.
  4. The code contains the pagelet (navbar.ascx) and a sample page using it.
  5. // By: Klemens Schmid (old)
  6. //
  7. //
  8. // Inputs:None
  9. //
  10. // Returns:None
  11. //
  12. //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.
  13. You can see the code in action at <a rel="nofollow" class="t" href="http://www.klemid.de/aspmenu.aspx" target="_blank">www.klemid.de/aspmenu.aspx</a>.
  14. Maybe you need my styles.css to make it look good.
  15. //
  16. //Side Effects:None
  17. //This code is copyrighted and has limited warranties.
  18. //Please see <a rel="nofollow" class="t" href="http://www.Planet-Source-Code.com/xq/ASP/txtCodeId.253/lngWId.10/qx/vb/scripts/ShowCode.htm" target="_blank">http://www.Planet-Source-Code.com/xq...s/ShowCode.htm</a>
  19. //for details.
  20. //**************************************
  21.  
  22. --------------------------------------------------
  23. Pagelet code:
  24. --------------------------------------------------
  25. <!-- navigation bar for klemid's web
  26. <script language="VB" runat="server">
  27. Dim MenuEntry(,) As object = { _
  28. {"Home", "welcome.aspx", "", true}, _
  29. {"Interests", "interests.aspx", "", true}, _
  30. {"My Tools", "tools.aspx", "", true}, _
  31. {"ASP.NET Menu", "aspmenu.aspx", "My Tools", false}, _
  32. {"SMS via http", "vbsms.aspx", "My Tools", false}, _
  33. {"OL2WAP", "ol2wap.aspx", "My Tools", false}, _
  34. {"Form Sniffer", "formsniffer2.aspx", "My Tools", false}, _
  35. {"Crypt File", "cryptfile.aspx", "My Tools", false}, _
  36. {"Copy Contacts", "copycontacts.aspx", "My Tools", false}, _
  37. {"eBay Reminder", "ebayrem.aspx", "My Tools", false}, _
  38. {"Fav2Web", "fav2web.aspx", "My Tools", false}, _
  39. {"Lex4VB", "lex4vb.aspx", "My Tools", false}, _
  40. {"M-Pad", "mpad.asp", "", true}, _
  41. {"My Charts", "mycharts.aspx", "", true}, _
  42. {"Select", "mycharts1.aspx", "My Charts", false}, _
  43. {"Display", "mycharts2.aspx", "My Charts", false}, _
  44. {"Urlaub", "urlaub.aspx", "", true}, _
  45. {"Ruhpolding", "ruhpolding.aspx", "Urlaub", false}, _
  46. {"Wiesloch", "wiesloch.aspx", "", true}, _
  47. {"Top 30 WapMarks", "topwap.aspx", "", true}, _
  48. {"Top 30 WebMarks", "topweb.aspx", "", true}, _
  49. {"All My WebMarks", "allweb.aspx", "", true}, _
  50. {"", "", "", true}, _
  51. {"Email", "mailto:feedback@schmidks.de?subject=Feedback", "", true}, _
  52. {"Disclaimer", "http://www.disclaimer.de/disclaimer.htm", "", true} _
  53. }
  54. Dim i as integer
  55. Dim strCurrentPage as String
  56. dim bSubmenuStarting as Boolean = false
  57.  
  58. Sub Page_Load(Source as Object, E as EventArgs)
  59. Dim i, j as Integer
  60. Dim strParent as String
  61.  
  62. 'switch on the submenu according to the currently displayed page
  63. strCurrentPage = Request.Url.Segments.GetValue(Request.Url.Segments.GetUpperBound(0))
  64. For i=0 To MenuEntry.GetUpperBound(0)
  65. If MenuEntry(i, 1) = strCurrentPage Then
  66. If MenuEntry(i, 2) = "" Then
  67. 'main menu item was clicked
  68. strParent = MenuEntry(i, 0)
  69. Else
  70. 'submenu item was clicked
  71. strParent = MenuEntry(i,2)
  72. End If
  73. 'found -> switch on the 'visible' flag for submenu items
  74. For j=0 To MenuEntry.GetUpperBound(0)
  75. If MenuEntry(j, 2) = strParent Then
  76. MenuEntry(j, 3) = True
  77. End If
  78. Next
  79. Exit For
  80. End If
  81. Next
  82. End Sub
  83. </script>
  84. -->
  85. <table cellspacing="1" cellpadding="3" bgcolor="white" align=center>
  86. <% for i=0 to MenuEntry.GetUpperBound(0) %>
  87. <% if MenuEntry(i,0) = "" Then 'separator line%>
  88. <tr>
  89. <td bgcolor="#dedebe" height="1">
  90. </tr>
  91. <tr>
  92. <td bgcolor="#dedebe" height="1">
  93. </tr>
  94. <% else 'normal link %>
  95. <% if i > 0 AndAlso MenuEntry(i-1, 2) <> "" AndAlso MenuEntry(i, 2) = "" AndAlso MenuEntry(i-1, 3) Then 'submenu ends %>
  96. </table>
  97. <% end if %>
  98. <% bSubmenuStarting = (i > 0 AndAlso MenuEntry(i, 2) <> "" AndAlso MenuEntry(i, 3) AndAlso MenuEntry(i+1, 2) = "") %>
  99. <% if bSubmenuStarting Then %>
  100. <td bgcolor="#f2f2e6" >
  101. <table border="0" cellspacing="0" bgcolor="#ececd9">
  102. <% end if %>
  103. <% if MenuEntry(i, 2) <> "" Then 'submenu entry %>
  104. <% if MenuEntry(i, 3) Then %>
  105. <tr>
  106. <td width="100%" bgcolor="#f2f2e6" <%= IIf(MenuEntry(i,1)=strCurrentPage, "style=""FONT-WEIGHT: bold""", "") %> >
  107. <font size="2"><nobr>
  108. <a href="<%= MenuEntry(i,1) %>" class="NavLink"><%= MenuEntry(i,0)%></a>
  109. </nobr></font>
  110. </td>
  111. </tr>
  112. <% End if%>
  113. <% else 'main menu %>
  114. <tr>
  115. <td bgcolor="#dedebe" height="18" <%= IIf(MenuEntry(i,1)=strCurrentPage, "style=""FONT-WEIGHT: bold""", "") %> >
  116. <nobr>
  117. <a href="<%= MenuEntry(i,1) %>" class="NavLink"><%= MenuEntry(i,0)%></a>
  118. </nobr>
  119. </td>
  120. </tr>
  121. <% end if %>
  122. <% end if %>
  123. <% next %>
  124. </table>
  125. --------------------------------------------------
  126. Sample page
  127. --------------------------------------------------
  128. <%@ Register TagPrefix="klemid" TagName="NavBar" Src="navbar.ascx" %>
  129. <%@ Page Language="vb" AutoEventWireup="true" Debug="true" %>
  130. <%@ Import namespace="System.IO" %>
  131. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
  132. <HTML>
  133. <HEAD>
  134. <title>ASP.NET Menu</title>
  135. <meta content="Microsoft Visual Studio.NET 7.0" name="GENERATOR">
  136. <meta content="Visual Basic 7.0" name="CODE_LANGUAGE">
  137. <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
  138. <meta http-equiv="Content-Language" content="en-us">
  139. <meta content="JavaScript" name="vs_defaultClientScript">
  140. <meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
  141. <LINK href="Styles.css" type="text/css" rel="stylesheet">
  142. <script id="fill" runat="server">
  143. Sub Page_Load(sender as object, e as System.EventArgs)
  144. Dim SReadToEnd As Stream
  145. 'read the pagelet
  146. SReadToEnd = File.OpenRead(Page.MapPath(".\navbar.ascx"))
  147. Dim SrReadToEnd As StreamReader = New StreamReader(SReadToEnd, _
  148. System.Text.Encoding.ASCII)
  149. 'SrReadToEnd.BaseStream.Seek(0, SeekOrigin.Begin)
  150. txtPagelet.Text = SrReadToEnd.ReadToEnd()
  151. SrReadToEnd.Close()
  152. 'read this page
  153. SReadToEnd = File.OpenRead(Page.MapPath(Page.Request.FilePath()))
  154. SrReadToEnd = New StreamReader(SReadToEnd, System.Text.Encoding.ASCII)
  155. 'SrReadToEnd.BaseStream.Seek(0, SeekOrigin.Begin)
  156. txtThisPage.Text = SrReadToEnd.ReadToEnd()
  157. SrReadToEnd.Close()
  158. End Sub
  159. </script>
  160. </HEAD>
  161. <body style="BACKGROUND-IMAGE: none" leftMargin="0" topMargin="0" marginheight="0" marginwidth="0">
  162. <table dir="ltr" height="100%" cellSpacing="0" cellPadding="10" width="100%" border="0">
  163. <tr>
  164. <td vAlign="top" bgColor="#cccc99">
  165. <!-- header --><klemid:navbar id="NavBar" runat="server"></klemid:navbar></td>
  166. <td vAlign="top" width="100%">
  167. <!-- actual body goes here --><a name="Oben"></a>
  168. <h2 align="center">ASP.NET Menu</h2>
  169. <p>
  170. <p style="MARGIN-TOP: 10px; MARGIN-BOTTOM: 5px" align="center">
  171. Inspect the source code of the menu seen on the left side
  172. <P>
  173. <P>
  174. <hr>
  175. See how the menu on the left side of my pages is implemented. It is done by an
  176. ASP.NET pagelet. Of course, you can buy a full-blown ASP.NET menu control like
  177. the ones found at <A href="http://www.asp.net">www.asp.net</A>
  178. , but those are not free and they are mostly overkill for a small web site
  179. having only one menu.
  180. <P></P>
  181. <P>Although the code here works only for ASP.NET it would be an easy exercise the
  182. adapt it for pure ASP.
  183. </P>
  184. <form runat="server">
  185. <P></P>
  186. <P>Pagelet code (navbar.ascx):</P>
  187. <P>
  188. <asp:TextBox id="txtPagelet" runat="server" Width="100%" Height="114px" TextMode="MultiLine" ReadOnly="True"></asp:TextBox></P>
  189. <P>This page's code:</P>
  190. <p></p>
  191. <asp:TextBox id="txtThisPage" runat="server" Width="100%" Height="114px" TextMode="MultiLine" DESIGNTIMEDRAGDROP="282" ReadOnly="True"></asp:TextBox>
  192. <P></P>
  193. <P> </P>
  194. </form>
  195. </td>
  196. </tr>
  197. </table>
  198. </body>
  199. </HTML>
  200.  


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, Pharmacy Informatics
Wordpress Learning Blog
Updated : ASP.Net Login Code
Reply With Quote Quick reply to this message  
Join Date: Feb 2002
Posts: 898
Reputation: Tekmaven is a glorious beacon of light Tekmaven is a glorious beacon of light Tekmaven is a glorious beacon of light Tekmaven is a glorious beacon of light Tekmaven is a glorious beacon of light 
Solved Threads: 26
Moderator
Tekmaven's Avatar
Tekmaven Tekmaven is offline Offline
The C# Man, Myth, Legend

Re: Drop Down Menu

 
0
  #3
Jul 3rd, 2004
A better solution would be skmMenu, an open-source ASP.NET based menu application.
-Ryan Hoffman

.NET Specialist / Webmaster, Extended64.com.
Please do not email or PM me with support questions. Please direct them to the forums instead.
Reply With Quote Quick reply to this message  
Join Date: Mar 2004
Posts: 634
Reputation: Slade has a spectacular aura about Slade has a spectacular aura about 
Solved Threads: 7
Slade's Avatar
Slade Slade is offline Offline
Practically a Master Poster

Re: Drop Down Menu

 
0
  #4
Jul 4th, 2004
Thanks very much tekmaven! That was VERY helpful!
Formerly known as Slade.
Reply With Quote Quick reply to this message  
Join Date: Feb 2002
Posts: 898
Reputation: Tekmaven is a glorious beacon of light Tekmaven is a glorious beacon of light Tekmaven is a glorious beacon of light Tekmaven is a glorious beacon of light Tekmaven is a glorious beacon of light 
Solved Threads: 26
Moderator
Tekmaven's Avatar
Tekmaven Tekmaven is offline Offline
The C# Man, Myth, Legend

Re: Drop Down Menu

 
0
  #5
Jul 5th, 2004
Just doing what Dani forces me to ;-).
-Ryan Hoffman

.NET Specialist / Webmaster, Extended64.com.
Please do not email or PM me with support questions. Please direct them to the forums instead.
Reply With Quote Quick reply to this message  
Join Date: Feb 2003
Posts: 793
Reputation: Paladine has a spectacular aura about Paladine has a spectacular aura about Paladine has a spectacular aura about 
Solved Threads: 26
Team Colleague
Paladine's Avatar
Paladine Paladine is offline Offline
Master Poster

Re: Drop Down Menu

 
0
  #6
Jul 5th, 2004
Forces.....Forces...hmmm, why do I find that hard to believe? Although Dani being forceful does have some interesting connotations to it.
Assistant Manager, Pharmacy Informatics
Wordpress Learning Blog
Updated : ASP.Net Login Code
Reply With Quote Quick reply to this message  
Join Date: Feb 2002
Posts: 898
Reputation: Tekmaven is a glorious beacon of light Tekmaven is a glorious beacon of light Tekmaven is a glorious beacon of light Tekmaven is a glorious beacon of light Tekmaven is a glorious beacon of light 
Solved Threads: 26
Moderator
Tekmaven's Avatar
Tekmaven Tekmaven is offline Offline
The C# Man, Myth, Legend

Re: Drop Down Menu

 
0
  #7
Jul 5th, 2004
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

.NET Specialist / Webmaster, Extended64.com.
Please do not email or PM me with support questions. Please direct them to the forums instead.
Reply With Quote Quick reply to this message  
Join Date: Feb 2003
Posts: 793
Reputation: Paladine has a spectacular aura about Paladine has a spectacular aura about Paladine has a spectacular aura about 
Solved Threads: 26
Team Colleague
Paladine's Avatar
Paladine Paladine is offline Offline
Master Poster

Re: Drop Down Menu

 
0
  #8
Jul 5th, 2004


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, Pharmacy Informatics
Wordpress Learning Blog
Updated : ASP.Net Login Code
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC