Loop Through Repeater control

pratikshahse used Ask the Experts™
Here is what I want:

I have 4-5 repeatercontrols on my page.  On a click of a button I want to loop through each repeater and get its name.

For example I have


Button click event

foreach (RepeaterItem repItems in repeater1.Items)

so when its the first loop i want to go through all the items of repeater1. next time around i want to go through repeater2 items and so on until it finds the last repeater on the page.

I hope I am making sense.

Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2014
public IEnumerable<Control> GetAll(Control control, Type type)
            var controls = control.Controls.Cast<Control>();

            return controls.SelectMany(ctrl => GetAll(ctrl, type))
                                      .Where(c => c.GetType() == type);

protected void btn_Click(object sender, EventArgs e)
            var c = GetAll(this, typeof(Repeater));
            foreach(Repeater rp in c)
                foreach(RepeaterItem item in rp.Items)
                    // whatever you want to get

Open in new window

I hope I get understand your question right and answer properly

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial