如何在ASP.NET中的菜单导航中显示和消失菜单 [英] How to do Menu appear and disappear in Menu Navigation in ASP.NET
本文介绍了如何在ASP.NET中的菜单导航中显示和消失菜单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有导航菜单.
根据我的表值条件,菜单应该出现和消失.
该怎么做?
查看我的ASPX代码
Hi,
I have the navigation menu.
Based on my table values condition, menu should appear and disappear.
How to do this?
See my ASPX Code
<asp:Menu id="NavigationMenu" Runat="Server" Orientation="Horizontal"
StaticMenuStyle-VerticalPadding="2"
StaticMenuItemStyle-Font-Name="Verdana"
StaticMenuItemStyle-Font-Size="9pt"
StaticMenuItemStyle-ForeColor="white"
StaticHoverStyle-BackColor="#707070"
StaticHoverStyle-ForeColor="white"
StaticSelectedStyle-Font-Bold="True"
StaticSelectedStyle-BackColor="black"
StaticSelectedStyle-ForeColor="RED">
<items>
<asp:MenuItem Text="Home" NavigateUrl="Home.aspx" >
<asp:MenuItem Text="Admin" NavigateUrl="A.aspx">
<asp:MenuItem Text="B" NavigateUrl="B.aspx">
<asp:MenuItem Text="C" NavigateUrl="C.aspx">
</items>
ASPX.VB代码
ASPX.VB Code
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
'-- Get page name from relative path
Dim ThisPage As String = Page.AppRelativeVirtualPath
Dim SlashPos As Integer = InStrRev(ThisPage, "/")
Dim PageName As String = Right(ThisPage, Len(ThisPage) - SlashPos)
'-- Select menu item with matching NavigateUrl property
Dim ParentMenu As MenuItem
Dim ChildMenu As MenuItem
For Each ParentMenu In NavigationMenu.Items
If ParentMenu.NavigateUrl = PageName Then
ParentMenu.Selected = True
Else
For Each ChildMenu In ParentMenu.ChildItems
If ChildMenu.NavigateUrl = PageName Then
ChildMenu.Selected = True
End If
Next
End If
Next
If Not IsPostBack Then
StrQry = ""
StrQry = " Select isnull(A,'') as Admin,isnull(Home,'') as Home,"
StrQry &= " isnull(B,'') as B,isnull(C,'') as C""
Conn.Open()
Cmd.Connection = Conn
Cmd.CommandText = StrQry
Rdr = Cmd.ExecuteReader
If Rdr.HasRows Then
While Rdr.Read
'Here I need to display the Menu if record is there.....
End While
End If
Rdr.Close()
Conn.Close()
End If
'check whether session expires
End Sub
推荐答案
我已经在几周前回答了类似的问题
您需要做的就是
仅根据用户权限过滤数据源&绑定到控件,仅此而已.
基于用户类型的菜单 [
Already I have answered a similar question few weeks ago
All you need to do is
just filter the datasource based on user rights & bind to control, that''s all.
Menus based on User type[^]
这篇关于如何在ASP.NET中的菜单导航中显示和消失菜单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文