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

  • SEARCH
  • Home
  • 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 7019963
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T23:15:21+00:00 2026-05-27T23:15:21+00:00

Hi im trying to solve this problem, I’m fetching data from DB and create

  • 0

Hi im trying to solve this problem, I’m fetching data from DB and create the menu:

  if (Context.User.IsInRole("Admin") == true)
  {


                mnMenu.Items.Clear();
                List<menuRole> menuParentList = new List<menuRole>();
                List<MenuItem> menuItemList = new List<MenuItem>();
                List<MenuItem> hoverItem = new List<MenuItem>();
                int parentPosition = 0;
                string menuName;

                menuParentList = roles.getMenuItems().ToList();

                for (int i = 0; i < menuParentList.Count; i++)
                {
                    if (menuParentList[i].menuType == "Admin")
                    {
                        if (menuParentList[i].MenuRole1 == "parent")
                        {
                            menuName = menuParentList[i].menuName.ToString();
                            menuItemList[i].Text = menuName;
                            parentPosition = i;
                        }
                        else if (menuParentList[i].MenuRole1 == "child")
                        {
                           hoverItem[i].Text = menuParentList[i].menuName;
                           hoverItem[i].NavigateUrl = menuParentList[i].MenuLink;
                           menuItemList[i].ChildItems.Add(hoverItem[i]);
                        }
                    }
                }
                mnMenu.Items.Add(menuItemList[0]);
                mnMenu.Items.Add(menuItemList[1]);
                mnMenu.Items.Add(menuItemList[2]);

      }

now its giving me this exception at the moment:

System.ArgumentOutOfRangeException was unhandled by user code
  Message=Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
  Source=mscorlib
  ParamName=index
  StackTrace:
       at System.ThrowHelper.ThrowArgumentOutOfRangeException()
       at System.Collections.Generic.List`1.get_Item(Int32 index)
       at PresentationLayer.UserControls.Menu.Page_Load(Object sender, EventArgs e) in C:\Users\Kurt\documents\visual studio 2010\Projects\aaa\PresentationLayer\UserControls\Menu.ascx.cs:line 44
       at System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e)
       at System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e)
       at System.Web.UI.Control.OnLoad(EventArgs e)
       at System.Web.UI.Control.LoadRecursive()
       at System.Web.UI.Control.LoadRecursive()
       at System.Web.UI.Control.LoadRecursive()
       at System.Web.UI.Control.LoadRecursive()
       at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
  InnerException: 
  • 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-05-27T23:15:22+00:00Added an answer on May 27, 2026 at 11:15 pm

    Well , this seems to make a few (too many) assumptions:

      mnMenu.Items.Add(menuItemList[2]);
    

    You should check how many items you got.


    if (menuParentList[i].MenuRole1 == "parent")
    {
      menuName = menuParentList[i].menuName.ToString();
      menuItemList.Add(new MenuItem());  // add this 
      menuItemList[i].Text = menuName;
      parentPosition = i;
    }
    

    And the same for HoverItem .


    Edit, take 3.

    You cannot use i to index the menuList and hoverItem collections, they don’t grow every step.

        if (menuParentList[i].MenuRole1 == "parent")
        {
            menuName = menuParentList[i].menuName.ToString();
            var newItem = new MenuItem();
            newItem.Text = menuName;
            menuItemList.Add(newItem);                             
            parentPosition = menuItemList.Count-1;   // flaky
        }
        else if (menuParentList[i].MenuRole1 == "child")
        {
            var newItem = new MenuItem();
            newItem.Text = menuParentList[i].menuName;
            newItem.NavigateUrl = menuParentList[i].MenuLink;
            hoverItem.Add(newItem);                             
    
            //menuItemList[i].ChildItems.Add(hoverItem[i]);
            menuItemList[parentPosition].ChildItems.Add(newItem);  // I think
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to solve this problem. I am reading data from csv fiile
I am trying to solve this problem from SPOJ, it's a dynamic programming problem,
Trying to solve this problem . I would like to learn how the bootstrapper
I am trying to solve this problem. I have a series of SELECT statements
I'm trying to solve this problem : http://uva.onlinejudge.org/external/7/732.html . For the given example, they
I've been trying to solve this problem for a number of days now but
I'm trying to solve this problem, its not a homework question, its just code
I have been trying to solve this problem for a while, but couldn't with
I'm trying to solve this flickering problem on the iphone (open gl es game).
I was trying to solve my XNA Font problem , when I found this

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.