how to create dynamic menu using c# in asp .net. i need with codings.. or with example.

Thanx in advance
Nithya

Hi Nithya. G,

I use EssentialObject menu control to create dynamic menu.

Sub CreateMenu()
        Dim MI As EO.Web.MenuItem
        Dim MII As EO.Web.MenuItem
        Dim MIII As EO.Web.MenuItem
        Dim Add As Boolean

        MyMenu.Items.Clear()
        MyMenu.EnableScrolling = True
        MyMenu.EnableViewState = False 
        MyMenu.ScrollDownLookID = "scroll_down"
        MyMenu.ScrollUpLookID = "scroll_up"
        MyMenu.ScrollSpeed = 100 

        Dim SQL As String
        Dim I As SByte = 0

        Dim CnMenu As New SqlClient.SqlConnection
        Dim CnSubMenu As New SqlClient.SqlConnection
        Dim CnFunction As New SqlClient.SqlConnection

        SQL = "Select MasterMainMenu.MainMenuID, MasterMainMenu.MainMenuName, MainMenuLink from MasterMainMenu order by Seq "
        GetCN(CnMenu)

        Dim CmMenu As New SqlClient.SqlCommand(SQL, CnMenu)
        Dim RdMenu As SqlClient.SqlDataReader
        RdMenu = CmMenu.ExecuteReader()
        Do While RdMenu.Read
            MI = New EO.Web.MenuItem
            MI.ItemID = RdMenu.Item("MainMenuID").ToString.Trim
            MI.Text.Html = RdMenu.Item("MainMenuName").ToString.Trim
            If RdMenu.Item("MainMenuLink").ToString.Trim <> "" Then MI.NavigateUrl = RdMenu.Item("MainMenuLink").ToString.Trim

            MI.HoverStyle.Font.Size = 8
            MI.HoverStyle.Font.Bold = True
            MI.NormalStyle.Font.Bold = True
            MI.NormalStyle.Font.Size = 8
            MI.HoverStyle.ForeColor = Drawing.Color.RoyalBlue
            MyMenu.Items.Add(MI)

            SQL = "Select FunctionID, SubMainMenuName, SubMainMenuID, FunctionLink from MasterSubMainMenu where MainMenuID='" & RdMenu.Item("MainMenuID").ToString.Trim & "' Order By Seq"
            GetCN(CnSubMenu)
            Dim CmSubMenu As New SqlCommand(SQL, CnSubMenu)
            Dim RdSubMenu As SqlClient.SqlDataReader
            RdSubMenu = CmSubMenu.ExecuteReader
            Do While RdSubMenu.Read
                MII = New EO.Web.MenuItem
                MII.ItemID = RdSubMenu.Item("SubMainMenuID").ToString.Trim
                MII.HoverStyle.ForeColor = Drawing.Color.Red
             
                MII.HoverStyle.Font.Size = 8
                MII.HoverStyle.Font.Bold = True
                MII.NormalStyle.Font.Bold = True
                MII.NormalStyle.Font.Size = 8
                MII.Text.Html = RdSubMenu.Item("SubMainMenuName").ToString.Trim

                If SetStringValue(RdSubMenu.Item("FunctionLink")) <> "" Then
                    If Security.IsUserAllowed(Session("UserId"), SetStringValue(RdSubMenu.Item("FunctionID")), UserAccess.CanDisplay) = True Then
                        MII.NavigateUrl = RdSubMenu.Item("FunctionLink").ToString.Trim
                        MII.Status = RdSubMenu.Item("FunctionLink").ToString.Trim
                        Add = True
                    End If
                Else
                    SQL = "Select MasterFunction.FunctionID,MasterFunction.FunctionName,FunctionLink, FunctionTarget from MasterUserFunctionDetail inner join MasterFunction On MasterFunction.FunctionID=MasterUserFunctionDetail.FunctionID where MasterUserFunctionDetail.UserID='" & Trim(Session("UserID")) & "' and MasterFunction.MainMenuID='" & SetStringValue(RdSubMenu.Item("SubMainMenuID")) & "' and ISNULL(DISABLED,'') = 'N' Order By MasterFunction.Seq "
                    GetCN(CnFunction) 

                    Dim CmFunction As New SqlCommand(SQL, CnFunction)
                    Dim RdFunction As SqlClient.SqlDataReader
                    RdFunction = CmFunction.ExecuteReader 
                    If RdFunction.HasRows = False Then
                        Add = False
                    Else
                        Do While RdFunction.Read
                            If Security.IsUserAllowed(Session("UserId"), RdFunction.Item("FunctionId").ToString.Trim, UserAccess.CanDisplay) = True Then
                                MIII = New EO.Web.MenuItem
                                MIII.ItemID = RdFunction.Item("FunctionId").ToString.Trim
                                MIII.HoverStyle.Font.Size = 8
                                MIII.HoverStyle.Font.Bold = True
                                MIII.HoverStyle.ForeColor = Drawing.Color.Red
                       
                                MIII.NormalStyle.Font.Bold = True
                                MIII.NormalStyle.Font.Size = 8
                                MIII.NavigateUrl = RdFunction.Item("FunctionLink").ToString.Trim
                                MIII.Status = RdFunction.Item("FunctionLink").ToString.Trim
                                MIII.Text.Html = RdFunction.Item("FunctionName").ToString.Trim
                                MIII.TargetWindow = RdFunction.Item("FunctionTarget").ToString.Trim
                                MII.SubMenu.Items.Add(MIII)
                            End If
                        Loop
                        Add = True
                    End If
                    SetToNothing(CnFunction, RdFunction, CmFunction)
                End If
                If Add = True Then MyMenu.Items(I).SubMenu.Items.Add(MII)
            Loop
            I = I + 1 
            SetToNothing(CnSubMenu, RdSubMenu, CmSubMenu)
        Loop
        SetToNothing(CnMenu, RdMenu, CmMenu)
    End Sub

Thanks,

Kusno.

thank u so much...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.