Click here to Skip to main content
15,890,123 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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 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
Posted
Updated 1-Aug-11 21:48pm
v2

1 solution

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[^]
 
Share this answer
 
Comments
gani7787 2-Aug-11 4:31am    
Hi,
Can you give me a solution as per my code...where i need to bind and how?
because, i am new for the menu creation..?
thatraja 2-Aug-11 8:58am    
Did you check that link in my answer?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900