Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7738783
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T08:21:21+00:00 2026-06-01T08:21:21+00:00

I am trying to create dynamic menus from the database using the following example

  • 0

I am trying to create dynamic menus from the database using the following example
http://www.dotnetfunda.com/articles/article1477-how-to-create-a-menu-in-aspnet-using-aspmenu-control.aspx

I a modified the Code which is posted below only displays the parent menu but doesn’t show the child menu, i am sure something is wrong while debugging the code i notice that it doesnt enter the foreach (DataRowView row in dvMenu) of AddChildItems Function

My SQL query is like

Select PageID, PageName,PageInternalLinkURL, PageInheritance from pg_Pages

Code snippet i am using

<asp:Menu ID="Menu1" runat="server" Orientation="Horizontal" >

// I am convert ds to table for now.
DataTable table = dsMenu.Tables[0]; ;
DataView dvMenu = new DataView(table);
dvMenu.RowFilter = "PageInheritance is NULL";
foreach (DataRowView row in dvMenu)
{
MenuItem menuItem = new MenuItem(row["PageName"].ToString(), row["PageId"].ToString());
menuItem.NavigateUrl = row["PageURL"].ToString() + "?PageId=" + row["PageId"] + "&Language=" + sLangCode;
Menu1.Items.Add(menuItem);
AddChildItems(dvMenu.Table, menuItem);
}

//Function to look for child menu
    private static void AddChildItems(DataTable table, MenuItem menuItem)
    {
        DataView viewItem = new DataView(table);
        viewItem.RowFilter = "PageInheritance = " + menuItem.Value;
        foreach (DataRowView childView in viewItem)
        {
            MenuItem childItem = new MenuItem(childView["PageName"].ToString(),
            childView["PageId"].ToString());
            childItem.NavigateUrl = childView["PageURL"].ToString();
            menuItem.ChildItems.Add(childItem);
            AddChildItems(table, childItem);
        }
    }

I am not sure what i am doing wrong. Based on my database it should show me child menus for row Page2. when AddChildItems function is called for the match child row it just skill the loop and doesn’t show any thing from the child rows.

OUTPUT with Current Code

HOME | Page2 | Page3 | Page4

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T08:21:23+00:00Added an answer on June 1, 2026 at 8:21 am

    Answer Nothing is wrong with the code or logic it was the SQL Query which was getting the wrong data after fixing the query it worked like charm.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to create some dynamic sql using the following code block firstSqlStatement
I'm trying to create a dynamic grid using ExtJS. The grid is built and
I am trying to create some dynamic html out of some data from db.
I am trying to create a dynamic bar in HTML using javascript. I have
i am trying to create a dynamic multioption select using dynamic values for a
I am trying to create a dynamic menu by reading an XML file using
I am trying to create dynamic excel sheet, with the help of php using
I'm trying to create dynamic balls by using a for loop. For some reason
I am trying to create a dynamic set of dropdown boxes, using jQuery/AJAX and
I am trying to create a dynamic CSS file using the Django templating engine

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.