panelbar is not collapsing

8 posts, 0 answers
  1. Anjali
    Anjali avatar
    101 posts
    Member since:
    Dec 2010

    Posted 23 Mar 2011 Link to this post

    I have a panel bar in a user control. I can see all the items in the panel bar and expand it too, but I cannot collapse the panel bar. below is my code
    if (!Page.IsPostBack)
            {
                CSModel.CsMenu menu = new CSModel.CsMenu();
      
      
                IList<CsMenuSection> getMenuItems = menu.GetAllItems();
                
                   foreach (CsMenuSection section in getMenuItems)
                   {
                       RadPanelItem newItem = new RadPanelItem(section.Text);
                       RadPanelBar1.Items.Add(newItem);
                       CsMenuItem item = new CsMenuItem();
                       for (int i = 0; i <= section.MenuItems.Count-1; i++)
                       {
                           RadPanelItem childItem = new RadPanelItem(section.MenuItems[i].Text);
                           RadPanelItem InternalChildItem = new RadPanelItem();
                           // add to the child
                           childItem.Items.Add(InternalChildItem);
                           // set the content
                           InternalChildItem.Value = section.MenuItems[i].Link;
                           newItem.Items.Add(childItem);
      
                       }
                      
      
                   }
            }
      
    My .aspx page is like this
      
    <table>
        <tr>
       
               <td>
                <telerik:RadScriptManager ID="RadScriptManager1" runat="server">
                </telerik:RadScriptManager>
                <telerik:RadPanelBar ID="RadPanelBar1" runat="server" ExpandMode="FullExpandedItem" Height="250px" >
                </telerik:RadPanelBar>
              
            </td>
          
          
        </tr>
      
      
      
      
    </table>
      
    My CsMenu section looks like this
      public IList<CsMenuSection> GetMenuItems()
            {
                // go to DB to find menu items.
                CsMenuSection section = new CsMenuSection("DataReview","");            
                section.AddMenuItem(new CsMenuItem("Score rep", "/RepScore/Index"));
                section.AddMenuItem(new CsMenuItem("Something else", "/something/something"));
      
                CsMenuSection section2 = new CsMenuSection("Section 2", "");
                section2.AddMenuItem(new CsMenuItem("Sample", "/repScoring/Selectreps"));            
      
      
                _menu_item_list.Add(section);
                _menu_item_list.Add(section2);
                return MenuItemList;
                 
                  
            }
  2. Shivers999
    Shivers999 avatar
    13 posts
    Member since:
    Feb 2010

    Posted 24 Mar 2011 Link to this post

    Try this. It's not tested on your code but I used it.
    if (!Page.IsPostBack)
    {
        CSModel.CsMenu menu = new CSModel.CsMenu();
        IList<CsMenuSection> getMenuItems = menu.GetAllItems();
        foreach (CsMenuSection section in getMenuItems)
        {
            RadPanelItem newItem = new RadPanelItem(section.Text);
            RadPanelBar1.Items.Add(newItem);
            CsMenuItem item = new CsMenuItem();
            for (int i = 0; i <= section.MenuItems.Count - 1; i++)
            {
                RadPanelItem childItem = new RadPanelItem(section.MenuItems[i].Text);
                RadPanelItem InternalChildItem = new RadPanelItem();
                // Bind the template
                InternalChildItem.ItemTemplate = new TextBoxTemplate();
                // add to the child 
                childItem.Items.Add(InternalChildItem);
                // set the content 
                InternalChildItem.Value = section.MenuItems[i].Link;
                newItem.Items.Add(childItem);
                InternalChildItem.DataBind();
            }
        }
    }

    You'll need this too.
    class TextBoxTemplate : ITemplate
    {
        public void InstantiateIn(Control container)
        {
            // create a new container object that has a text porperty
            Label label1 = new Label();
            label1.ID = "ItemLabel";
            label1.DataBinding += new EventHandler(label1_DataBinding);
            container.Controls.Add(label1);
        }
        private void label1_DataBinding(object sender, EventArgs e)
        {
            Label target = (Label)sender;
            RadPanelItem item = (RadPanelItem)target.BindingContainer;
            string itemText = (string)DataBinder.Eval(item, "Value");
            target.Text = itemText;
        }
    }

  3. Anjali
    Anjali avatar
    101 posts
    Member since:
    Dec 2010

    Posted 25 Mar 2011 Link to this post

    Hi Shivers,

    where can I get the : ITemplate from? Am I missing any namespace?

    Please let me know.
    My Gui is like this

    <table  style="text-align:left"  >
        <tr >
       
               <td >
                <telerik:RadScriptManager ID="RadScriptManager1" runat="server">
                </telerik:RadScriptManager>
                <telerik:RadPanelBar ID="RadPanelBar1" runat="server"  Height="250px" >
                </telerik:RadPanelBar>
               
            
                  </td>
          
          
        </tr>
      
      
      
      
    </table>


    Thanks.
  4. Shivers999
    Shivers999 avatar
    13 posts
    Member since:
    Feb 2010

    Posted 25 Mar 2011 Link to this post

    System.Web.UI
  5. Anjali
    Anjali avatar
    101 posts
    Member since:
    Dec 2010

    Posted 25 Mar 2011 Link to this post

    Hi Shivers,

       Everythig looks fine except those link are not clickable so I can see
    /repScore/repscore.aspx, but I cannot clcik on it.

    is it possible to make them clcikable so that they can go to /repScore/repscore.aspx page.

    Thanks.

  6. Shivers999
    Shivers999 avatar
    13 posts
    Member since:
    Feb 2010

    Posted 25 Mar 2011 Link to this post

    In the TemplateBoxtemplate class, change the labels to hyperlink controls and set the 'Text' and 'NavigateURL' properties.
  7. Anjali
    Anjali avatar
    101 posts
    Member since:
    Dec 2010

    Posted 25 Mar 2011 Link to this post

    Thanks Shivers!! Everyhting looks great!! Links are working too. Just a qucik question. In my following menu model

    public IList<csMenuSection> GetMenuItems()
           {
               // go to DB to find menu items.
               csMenuSection section = new csMenuSection("DataReview","");            
               section.AddMenuItem(new csMenuItem("Score rep", "/RepScore/Index"));
               section.AddMenuItem(new csMenuItem("Something else", "/something/something"));
               csMenuSection section2 = new csMenuSection("Section 2", "");
               section2.AddMenuItem(new csMenuItem("Sample", "/repScoring/Selectreps"));            
               _menu_item_list.Add(section);
               _menu_item_list.Add(section2);
               return MenuItemList;
                
                 
           }
    In my panel bar, i want to see datareview and "score Rep" and "something else" underneath it. If I click on score rep, it should go to "/RepScore/Index" link. I don't want the link to be shown. Right now I am seeing "score Rep"  and then as I expand it, I see "/RepScore/Index" link too. I want the "score Rep" to behave as link.

    is it possible to do.

    Thanks, Sorry, i keep asking you questions.
  8. Shivers999
    Shivers999 avatar
    13 posts
    Member since:
    Feb 2010

    Posted 25 Mar 2011 Link to this post

    It's ok. But I'm headed to vacation for a week in 2 hours, so I'll be out of touch. 
    RadPanelItems have a NavigateURL property. Just set it to the link.

    Maybe like this...
    RadPanelItem childItem = new RadPanelItem(section.MenuItems[i].Text);
    childItem.NavigateUrl = section.MenuItems[i].Link;

Back to Top