locked
Problem Adding Manu Dynamically RRS feed

  • Question

  • User1978473002 posted

    Good Day All

    I have a code that add the Menu's Dynamically, the First item on the menu should be "Choose" and i am adding items from a List<string> and the code that does that is look.

    ParentRecordsRow[0] = "EVENT"
    ParentRecordsRow[1] = "CLASS"


    and the count is 2

    RadMenu1.Flow = ItemFlow.Vertical;
    //Add the Root
    RadMenuItem item = new RadMenuItem("Choose");
    //item.Text = "Add New Items";
    RadMenu1.Items.Add(item);
    //Bind Men
    for (int KK = 0; KK < ParentRecordsRow.Count ; KK++)
    {
            RadMenuItem itemSeparator = new RadMenuItem();
     
            RadMenuItem childItem = new RadMenuItem(ParentRecordsRow[KK]);
            //add the menu items
            item.Text = ParentRecordsRow[KK];
            //item.ImageUrl = "~/images/o!logo.png";
            item.Items.Add(childItem);
           
    }
    

    ok now the items gets Binded but i get "Events" Item as the First Item, like ITem Header and where it is i want the test "Choose" Now , i have attached the Screen-shot

    What i am i doing wrong





    Kind Regards

    Vuyiswa


    Monday, August 30, 2010 3:37 AM

Answers

  • User277293199 posted

    this happened because you are changing the text of the header item each time in the for loop, so you have to remove or comment this line :

    item.Text = ParentRecordsRow[KK];

    because item is the parent item not the child that's why it was set to Event


    your code should be like this:

    RadMenu1.Flow = ItemFlow.Vertical;  
    //Add the Root  
    RadMenuItem item = new RadMenuItem("Choose");  
    //item.Text = "Add New Items";  
    RadMenu1.Items.Add(item);  
    //Bind Men  
    for (int KK = 0; KK < ParentRecordsRow.Count ; KK++)  
    {  
            RadMenuItem itemSeparator = new RadMenuItem();  
       
            RadMenuItem childItem = new RadMenuItem(ParentRecordsRow[KK]);  
            //add the menu items  
            item.Items.Add(childItem);  
             
    }  



    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, August 30, 2010 6:16 AM

All replies

  • User277293199 posted

    this happened because you are changing the text of the header item each time in the for loop, so you have to remove or comment this line :

    item.Text = ParentRecordsRow[KK];

    because item is the parent item not the child that's why it was set to Event


    your code should be like this:

    RadMenu1.Flow = ItemFlow.Vertical;  
    //Add the Root  
    RadMenuItem item = new RadMenuItem("Choose");  
    //item.Text = "Add New Items";  
    RadMenu1.Items.Add(item);  
    //Bind Men  
    for (int KK = 0; KK < ParentRecordsRow.Count ; KK++)  
    {  
            RadMenuItem itemSeparator = new RadMenuItem();  
       
            RadMenuItem childItem = new RadMenuItem(ParentRecordsRow[KK]);  
            //add the menu items  
            item.Items.Add(childItem);  
             
    }  



    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, August 30, 2010 6:16 AM
  • User1978473002 posted

    Thanks

    i think i was sleeping :)

    Monday, August 30, 2010 9:29 AM
  • User277293199 posted

    never mind, you are welcome Wink

    Monday, August 30, 2010 9:32 AM
  • User1978473002 posted

    Wink


    Monday, August 30, 2010 9:36 AM