how can i create hierarcihal menu from database?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • wastman
    New Member
    • Apr 2009
    • 17

    how can i create hierarcihal menu from database?

    Code:
            SqlDataAdapter dadSubCat = new SqlDataAdapter();
            dadSubCat.SelectCommand = new SqlCommand("SELECT ID,PID,Title FROM Page where userid='user1'", con);
            DataSet dsCat = new DataSet();
            dadSubCat.Fill(dsCat, "Page");
            dsCat.Relations.Add("ParentChild", dsCat.Tables["Page"].Columns["ID"], dsCat.Tables["Page"].Columns["PID"], true);
            int count = 0;
            foreach (DataRow categoryRow in dsCat.Tables["Page"].Rows)
            {
                DataRow[] subCatRows = categoryRow.GetChildRows("ParentChild");
                if (categoryRow.GetParentRows("ParentChild").Length == 0)
                {
                    skmMenu.MenuItem mNode = new skmMenu.MenuItem("<img src=\"menublip.gif\" align=\"absmiddle\">" + categoryRow["Title"].ToString(), "");
    
                    foreach (DataRow row in subCatRows)
                    {
                        string Title = row["Title"].ToString();
                        mNode.SubItems.Add(new skmMenu.MenuItem(Title, ""));
                       
    
                    }
                    
                   Menu1.Items.Add(mNode);
                }
    
            }
    i can put for one sub menu but in case of multiple sub menu,is there a possible easy way for that one?
  • wastman
    New Member
    • Apr 2009
    • 17

    #2
    can any moderator help me out of this?

    can any moderator help me out of this problem, instead of locking me from this post?

    Comment

    • wastman
      New Member
      • Apr 2009
      • 17

      #3
      Please help me

      please help me for the above post.
      Last edited by wastman; May 1 '09, 01:10 PM. Reason: is my post visible or not,how should i write?

      Comment

      • tlhintoq
        Recognized Expert Specialist
        • Mar 2008
        • 3532

        #4
        I think I would store store a value of the Parent name... then at creation time search through all the existing menu items until I find the parent name, then make the new item a child of that. That should let you keep going several layers deep, so long as you don't have repeats of menu entries. You couldn't have a "Save" under "Images" and a "Save" under "Documents" for example. If the stored parent name is null, then it must be a root level menu. If the stored value is not null, but doesn't exist in a given menu, then the stored name is the root level to make first.

        Comment

        • tlhintoq
          Recognized Expert Specialist
          • Mar 2008
          • 3532

          #5
          Yesterday, 01:02 AM - Original post
          Today, 12:41 AM - bump (to be polite about it)
          Today, 06:08 AM - bump

          Dude... Relax and have some patience with the volunteers here. This isn't a site where you are paying people for tech support. Anyone with the background to give you help probably has a job and is not just sitting around the computer waiting for questions. Some experts check the site once a day, others throughout the day while at the office, but not from home, others only from home but can't during the work day. etc. At the moment I am doing an installation in a foreign country and am limited to when this 3rd world internet is working, and I'm not installing computers down in one of the caves (really, in caves.)

          Instead of just waiting for someone to reply to your question... Maybe there are other areas of your program you could work on and come back to the menus later... or you could experiment with several different ways of doing the menus. Finding alternative perspectives and alternative approaches is vital do this line of work.

          Comment

          • Hamayun Khan
            New Member
            • Aug 2007
            • 106

            #6
            Originally posted by wastman
            Code:
                    SqlDataAdapter dadSubCat = new SqlDataAdapter();
                    dadSubCat.SelectCommand = new SqlCommand("SELECT ID,PID,Title FROM Page where userid='user1'", con);
                    DataSet dsCat = new DataSet();
                    dadSubCat.Fill(dsCat, "Page");
                    dsCat.Relations.Add("ParentChild", dsCat.Tables["Page"].Columns["ID"], dsCat.Tables["Page"].Columns["PID"], true);
                    int count = 0;
                    foreach (DataRow categoryRow in dsCat.Tables["Page"].Rows)
                    {
                        DataRow[] subCatRows = categoryRow.GetChildRows("ParentChild");
                        if (categoryRow.GetParentRows("ParentChild").Length == 0)
                        {
                            skmMenu.MenuItem mNode = new skmMenu.MenuItem("<img src=\"menublip.gif\" align=\"absmiddle\">" + categoryRow["Title"].ToString(), "");
            
                            foreach (DataRow row in subCatRows)
                            {
                                string Title = row["Title"].ToString();
                                mNode.SubItems.Add(new skmMenu.MenuItem(Title, ""));
                               
            
                            }
                            
                           Menu1.Items.Add(mNode);
                        }
            
                    }
            i can put for one sub menu but in case of multiple sub menu,is there a possible easy way for that one?


            look into the Display Hierarchical Data with TreeView in ASP.NET 2.0

            Comment

            Working...