This is a migrated thread and some comments may be shown as answers.

Selecting a PanelBar that was generated dynamically and Expanding all Items

2 Answers 28 Views
PanelBar
This is a migrated thread and some comments may be shown as answers.
Kevin
Top achievements
Rank 1
Kevin asked on 06 May 2013, 07:08 PM
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 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 07 May 2013, 09:20 AM
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
0
Kevin
Top achievements
Rank 1
answered on 07 May 2013, 03:03 PM
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
Tags
PanelBar
Asked by
Kevin
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Kevin
Top achievements
Rank 1
Share this question
or