Selecting a PanelBar that was generated dynamically and Expanding all Items

3 posts, 0 answers
  1. Kevin
    Kevin avatar
    15 posts
    Member since:
    Mar 2013

    Posted 06 May 2013 Link to this post

    Hi,

    I have an app which creates multiple panelbars at runtime dynamically.
    When the user clicks a RadButton at the top, I want to expand all the items for the PanelBars.

    How would I select the PanelBar's that I created dynamically? 
    Is it better to do it from the Client Side using Javascript or the server side?

    Thanks in advance.

    Kevin
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 07 May 2013 Link to this post

    Hi,

    Try the following.
    c#
    protected void Button2_Click1(object sender, EventArgs e)
    {
            foreach (RadPanelItem item in RadPanelBar1.GetAllItems())
            {
                if (item.Items.Count > 0)
                {
                    item.Expanded = true;
                }
            }
    }

    Thanks,
    Shinu
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Kevin
    Kevin avatar
    15 posts
    Member since:
    Mar 2013

    Posted 07 May 2013 Link to this post

    Shinu,

    Thanks for the reply. That approach will work if you know the name of the PanelBar you are expanding ahead of time.

    Since I have multiple panelbars which are created dynamically at run time, I had to take a different approach.
    I created a hidden field on the page which would store a value of 1 or 2 depending on whether I wanted to collapse or expand all the panelbars.

    In my ExpandAll button I set the hiddenvalue to 1.
    protected void RadButtonExpandAll_Click(object sender, EventArgs e)
            {
                hdExpand.Value = "1";
            }

    In my CollapseAll button I set the hiddenvalue to 2.
    protected void RadButtonCollapseAll_Click(object sender, EventArgs e)
            {
                hdExpand.Value = "2";
            }

    When the postback occurs after clicking the ExpandAll or CollapseAll my code behind rebuilds all the panelbars. I check to see what the value of the hidden field is. If it is 1 I open the panel bars up. If it is 2 I collapse all of them.

    I initially set the hiddenvalue to 0 when the page loads for the first time so it does not open them until they click the expand all button.

    Kevin
Back to Top