javascript - Novice Menu/SubMenu issue -
i still new asp.net web programming can me out. have horizontal mainmenu , horizontal submenu directly under it.
i loading these database menucollection session variable dictionary of submenu , it's parentid.
when user clicks mainmenu item want swap in , display correct submenu.
when mainmenu.menuitemclick
event happens postback occurs , try put correct menu dictionary submenu doesn't show.
do need postback submenu load or need javascript? or going wrong way?
below code. thanks.
imports system.data imports system.data.sqlclient imports system.collections.generic public class rootmaster inherits system.web.ui.masterpage private readonly connection string = system.configuration.configurationmanager.connectionstrings("connectionstring").connectionstring protected sub page_load(byval sender object, byval e system.eventargs) handles me.load if not ispostback session("menudata") = getmenudata() addtopmenuitems(session("menudata")) end if end sub private function getmenudata() datatable using con new sqlconnection(connection) dim cmd new sqlcommand("select * menudata", con) dim dtmenuitems new datatable() dim sda new sqldataadapter(cmd) sda.fill(dtmenuitems) cmd.dispose() sda.dispose() return dtmenuitems end using end function private sub addtopmenuitems(menudata datatable) dim view dataview = nothing dim menudictionary new dictionary(of integer, menu) view = new dataview(menudata) view.rowfilter = "parentid null" each row datarowview in view 'adding menu item' if row("isactive") dim rowid integer = row("id") dim newmenuitem new menuitem(row("text").tostring(), rowid.tostring()) newmenuitem.navigateurl = row("navigateurl").tostring() mainmenu.items.add(newmenuitem) 'create sub menus each main menu item, add dictionary' dim subm = createsubmenus(menudata, newmenuitem) if subm.items.count > 0 menudictionary.add(rowid, subm) end if end if next session("menucollection") = menudictionary mainmenu.items(0).selected = true view = nothing end sub private function createsubmenus(menudata datatable, parentmenuitem menuitem) menu dim view dataview = nothing dim result new menu view = new dataview(menudata) view.rowfilter = "parentid=" & parentmenuitem.value each row datarowview in view if row("isactive") dim newmenuitem new menuitem(row("text").tostring(), row("id").tostring()) newmenuitem.navigateurl = row("navigateurl").tostring() result.items.add(newmenuitem) end if next return result end function protected sub mainmenu_itemclick(source object, e menueventargs) handles mainmenu.menuitemclick if not session("menucollection") nothing dim menudictionary dictionary(of integer, menu) = directcast(session("menucollection"), dictionary(of integer, menu)) if menudictionary.containskey(e.item.value) submenu = menudictionary.item(e.item.value) end if end if end sub end class
would possible redrawing of sub menu on prerender event. so, example:
protected sub mainmenu_itemclick(source object, e menueventargs) handles mainmenu.menuitemclick if not session("menucollection") nothing dim menudictionary dictionary(of integer, menu) = directcast(session("menucollection"), dictionary(of integer, menu)) if menudictionary.containskey(e.item.value) submenu = menudictionary.item(e.item.value) end if end if end sub
might become:
protected sub mainmenu_prerender(byval sender object, byval e eventargs) handles mainmenu.prerender if not session("menucollection") nothing dim menudictionary dictionary(of integer, menu) = directcast(session("menucollection"), dictionary(of integer, menu)) if menudictionary.containskey(e.item.value) submenu = menudictionary.item(e.item.value) end if end if end sub
if isn't working i'm afraid i'm not beyond that, thought though. figure if problem need preload menu using prerender maybe solve it.
Comments
Post a Comment