[CLOSED] accordion menu in codebehind

  1. #1

    [CLOSED] accordion menu in codebehind

    please help me take a look at this code, why i getting the name 'MP' dose not exist in the current context? Thank y ou for your help
    
    
    
    foreach (DataRow da in objUser.Rows)
    
    
    {
    if ((int)da["ParentMenuID"] == 0)
    {
    MenuPanel MP = new MenuPanel();
    MP.Title = da["MenuTitle"].ToString();
    Accordion1.Items.Add(MP); 
    }
    else
    {
    Ext.Net.Menu M = new Ext.Net.Menu();
    M.ID = "M";
    Ext.Net.MenuItem MI = new Ext.Net.MenuItem();
    MI.Text = "M1";
    MP.Menu.Items.Add(MI);
    }
    }
  2. #2

    RE: [CLOSED] accordion menu in codebehind

    any idea? thank you for your help
  3. #3

    RE: [CLOSED] accordion menu in codebehind

    Hi,

    Just incorrect variable scope. Please read the following articles
    http://msdn.microsoft.com/en-us/libr...32(VS.71).aspx
    http://www.csharpuniversity.com/2009...f-c-variables/


    Just remove MenuPanel declaration outside for loop and set null initialization value (otherwise you will get compiler error 'Local variable MP might not be initialized before accessing')
    MenuPanel MP = null;      foreach (DataRow da in objUser.Rows)

    Just you have strange construction. What if menu items will be defined in the objUser.Rows early then 'ParentMenuID'? You will get NullReference exception in this case because MenuPanel is not instantiated yet
  4. #4

    RE: [CLOSED] accordion menu in codebehind

    Thank you for your help. You are right about the if statement, that is not going to work. Reconstructed it using a couple for loop instead. thank you!

Similar Threads

  1. Replies: 2
    Last Post: Apr 02, 2012, 7:48 AM
  2. Replies: 5
    Last Post: Nov 11, 2010, 7:33 PM
  3. Replies: 1
    Last Post: Sep 22, 2010, 7:07 AM
  4. Accordion not showing in codebehind
    By lisaloomh in forum 1.x Help
    Replies: 1
    Last Post: Mar 12, 2009, 2:41 AM
  5. Replies: 7
    Last Post: Jan 21, 2009, 2:20 AM

Posting Permissions