Chat
Articles
Forums
$1000 Contest
FAQs
Groups
News
Software
About Us
Free Icons
RSS
Twitter
Generate Server Side Dropdown Menues
By Robbe D. Morris
Printer Friendly Version
Robbe & Melisa Morris
There a dozens of examples of how to create client side drop down menus in JavaScript. At
EggHeadCafe.com
, we really needed a simpler version that we could generate from server side ASP code. The code example you see below could easily be modified to pull the menu items out of a database file or XML. Since our values are fairly static, we hard coded the array values.
Feel free to take the code and modify it to fit your needs...
<% Response.Buffer = True Response.AddHeader "cache-control", "private" Response.AddHeader "pragma", "no-cache" Response.ExpiresAbsolute = #January 1, 1990 00:00:01# Response.Expires=0 Sub WriteTopMenuDropDown(sURL,nListNum) dim sArray dim nTot Select Case nListNum Case 1 nTot = 5 Redim sArray(1,nTot) sArray(0,1) = sURL & "/default.asp" sArray(1,1) = "Home Page" sArray(0,2) = sURL & "/aboutus.asp" sArray(1,2) = "About Us" sArray(0,3) = sURL & "/login/default.asp" sArray(1,3) = "Create/Update Profile" sArray(0,4) = sURL & "/services.asp" sArray(1,4) = "Development Services" sArray(0,5) = sURL & "/searchcontent.asp" sArray(1,5) = "Search Content" Case 2 nTot = 2 Redim sArray(1,nTot) sArray(0,1) = sURL & "/webservices.asp" sArray(1,1) = "Web Services" sArray(0,2) = sURL & "/notificationservicesubscribe.asp" sArray(1,2) = "Critical Updates" Case 3 nTot = 5 Redim sArray(1,nTot) sArray(0,1) = sURL & "/articles.asp" sArray(1,1) = "Articles" sArray(0,2) = sURL & "/codeexamples.asp" sArray(1,2) = "Code Examples" sArray(0,3) = sURL & "/tipstricks.asp" sArray(1,3) = "Tips & Tricks" sArray(0,4) = sURL & "/reviews.asp" sArray(1,4) = "Reviews" sArray(0,5) = sURL & "/software.asp" sArray(1,5) = "Software" Case 4 nTot = 5 Redim sArray(1,nTot) sArray(0,1) = sURL & "/forums/default.asp" sArray(1,1) = "Forum Listing" sArray(0,2) = sURL & "/forums/forumtree.asp?ID=2" sArray(1,2) = "C#" sArray(0,3) = sURL & "/forums/forumtree.asp?ID=3" sArray(1,3) = "JavaScript" sArray(0,4) = sURL & "/forums/forumtree.asp?ID=4" sArray(1,4) = "XML/XSL" sArray(0,5) = sURL & "/forums/forumtree.asp?ID=5" sArray(1,5) = "ASP" End Select WriteTopMenuList "TopList",nListNum,sArray,nTot End Sub Sub WriteTopMenu(fIncludeURL) dim sURL dim sT1 sT1 = "
" RW "
" RW sT1 & "(event,1); >
" RW sT1 & "(event,2); >
" RW sT1 & "(event,3); >
" RW sT1 & "(event,4); >
" RW "
" RW "
" WriteTopMenuDropDown sURL,1 WriteTopMenuDropDown sURL,2 WriteTopMenuDropDown sURL,3 WriteTopMenuDropDown sURL,4 RW vbcrlf & vbcrlf & vbcrlf & vbcrlf & vbcrlf End Sub Sub WriteTopMenuList(sListName,nListNum,sArray,nTot) Dim nCnt RWJS "
" RWJS "
" RW "
" RW "
" For nCnt = 1 To nTot RW "
" RW "
" RW sArray(1,nCnt) & "
" RW "
" Next RW "
" RW "
" RW "
" End Sub Sub RW(sVal) Response.Write sVal & vbcrlf End Sub Sub RWJS(sVal) Response.Write sVal End Sub Sub WriteTopMenuJS() RWJS "" End Sub ' Test page code begins here...You may take this out for your pages... RW "" RW "
" RW "" RW "
" RW "
" WriteTopMenuJS WriteTopMenu 1 RW "
" RW "
" RW "" RW "" %>
Robbe has been a Microsoft MVP in C# since 2004. He is also the co-founder of EggHeadCafe which provides .NET articles, book reviews, software reviews, and software download and purchase advice.