944,006 Members | Top Members by Rank

Ad:
  • ASP.NET Discussion Thread
  • Marked Solved
  • Views: 55498
  • ASP.NET RSS
Jun 29th, 2004
0

Drop Down Menu

Expand Post »
Hi, I need to know how I would go about making a drop down menu in asp .net using vb .net...

Thanks,

Slade
Similar Threads
Reputation Points: 115
Solved Threads: 7
Practically a Master Poster
Slade is offline Offline
633 posts
since Mar 2004
Jul 3rd, 2004
0

Re: Drop Down Menu

Quote 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!

ASP.NET Syntax (Toggle Plain Text)
  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" 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" 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
Team Colleague
Reputation Points: 211
Solved Threads: 27
Master Poster
Paladine is offline Offline
793 posts
since Feb 2003
Jul 3rd, 2004
0

Re: Drop Down Menu

A better solution would be skmMenu, an open-source ASP.NET based menu application.
Moderator
Reputation Points: 322
Solved Threads: 28
The C# Man, Myth, Legend
Tekmaven is offline Offline
914 posts
since Feb 2002
Jul 4th, 2004
0

Re: Drop Down Menu

Thanks very much tekmaven! That was VERY helpful!
Reputation Points: 115
Solved Threads: 7
Practically a Master Poster
Slade is offline Offline
633 posts
since Mar 2004
Jul 5th, 2004
0

Re: Drop Down Menu

Just doing what Dani forces me to ;-).
Moderator
Reputation Points: 322
Solved Threads: 28
The C# Man, Myth, Legend
Tekmaven is offline Offline
914 posts
since Feb 2002
Jul 5th, 2004
0

Re: Drop Down Menu

Forces.....Forces...hmmm, why do I find that hard to believe? Although Dani being forceful does have some interesting connotations to it.
Team Colleague
Reputation Points: 211
Solved Threads: 27
Master Poster
Paladine is offline Offline
793 posts
since Feb 2003
Jul 5th, 2004
0

Re: Drop Down Menu

Quote 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
Moderator
Reputation Points: 322
Solved Threads: 28
The C# Man, Myth, Legend
Tekmaven is offline Offline
914 posts
since Feb 2002
Jul 5th, 2004
0

Re: Drop Down Menu



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!
Team Colleague
Reputation Points: 211
Solved Threads: 27
Master Poster
Paladine is offline Offline
793 posts
since Feb 2003

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in ASP.NET Forum Timeline: ASP .NET database hit counter
Next Thread in ASP.NET Forum Timeline: Error with manifest resource files





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC