Results 1 to 1 of 1

Thread: using ddlevelsmenu with database

  1. #1
    Join Date
    Jun 2013
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default using ddlevelsmenu with database

    1- Script Title: ddlevelsmenu

    2- Script URL (on DD):
    http://www.dynamicdrive.com/dynamicindex1/ddlevelsmenu/

    3- Describe problem:
    Iam using the cool menu ddlevelsmenu (http://www.dynamicdrive.com/dynamici...menu/index.htm
    I want to get the menu items from a database..
    my aspx file contain the menu and it works fine as static menu (hard coded) :

    My table: {
    Code:
    IdPage int, PageTitle varchar(20), PageFileUrl varchar(30), ParentIdPage int
    }


    and the code behind:
    Code:
     private void AddParentMenuItems(int userId)
        {
            GetMenuData(userId);
    
            DataRow[] dataRowParent = _dataTable.Select("[ParentIdPage]=" + 0);
    
            foreach (DataRow dr in dataRowParent)
            {
                HtmlGenericControl li = new HtmlGenericControl("li");
                //  add <a> 
                HtmlGenericControl hlink = new HtmlGenericControl("a");
    
                if (dr["PageFileUrl"].ToString() == "") // with submenu.
                {
                    li.Attributes.Add("rel", "ddsubmenu" + dr["IdPage"].ToString());
                    
                    hlink.Attributes.Add("href", "#");
                    hlink.InnerText = dr["PageTitle"].ToString();
                    li.Controls.Add(hlink);
    
                    ulTopMenu.Controls.Add(li);
                   
                    
                    AddNewUl((int)dr["IdPage"]);
                    AddSubmenuItems(_dataTable, (int)dr["IdPage"]);
                 }
                else // no submenu
                {
                    hlink.Attributes.Add("href", dr["PageFileUrl"].ToString());
                    hlink.InnerText = dr["PageTitle"].ToString();
                    li.Controls.Add(hlink);
    
                    ulTopMenu.Controls.Add(li);
                }
    
            }
            // 
        }
     
        private void AddSubmenuItems(DataTable dataTable, int menuId)
        {
            // create related sub menu  
            DataView dataView = new DataView(dataTable);
            dataView.RowFilter = "ParentIdPage=" + menuId;
    
            foreach (DataRowView subMenuItem in dataView)
            {
                HtmlControl ulControl = (HtmlControl)FindControl("ddsubmenu" + menuId);
                HtmlGenericControl li = new HtmlGenericControl("li");
                HtmlGenericControl hlink = new HtmlGenericControl("a");
                hlink.Attributes.Add("href", subMenuItem["PageFileUrl"].ToString());
                hlink.InnerText = subMenuItem["PageTitle"].ToString();
                
                li.Controls.Add(hlink);
                li.InnerText = subMenuItem["PageTitle"].ToString();
                li.Attributes.Add("href", subMenuItem["PageFileUrl"].ToString());
    
                ulControl.Controls.Add(li);
            }
        }
        //
        private void AddNewUl(int menuId)
        {
             HtmlGenericControl newUl = new HtmlGenericControl("ul");
             newUl.ID = "ddsubmenu" + menuId;
            newUl.Attributes.Add("class", "ddsubmenustyle");
            newUl.Attributes.Add("dir", "rtl");
            placeHolder1.Controls.Add(newUl);
        
        }
        
        protected void Page_Load(object sender, EventArgs e)
        {
            AddParentMenuItems(-1);
        }
    My Problem is: the submenu does not appear at all.. any help ?
    Last edited by mohtigan; 06-21-2013 at 11:45 PM. Reason: Reform the post: adding 1) Script Title: 2) Script URL

Similar Threads

  1. ddlevelsmenu
    By peleve in forum Dynamic Drive scripts help
    Replies: 5
    Last Post: 01-09-2013, 05:14 PM
  2. ddlevelsmenu
    By dumorim in forum Dynamic Drive scripts help
    Replies: 2
    Last Post: 06-19-2011, 05:01 PM
  3. ddlevelsmenu
    By artman in forum Dynamic Drive scripts help
    Replies: 1
    Last Post: 03-04-2011, 09:30 PM
  4. ddlevelsmenu
    By aliced in forum Dynamic Drive scripts help
    Replies: 2
    Last Post: 12-04-2009, 04:18 PM
  5. Help with ddlevelsmenu?
    By Speedy turtle in forum Dynamic Drive scripts help
    Replies: 3
    Last Post: 07-25-2008, 08:55 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •