How to loop through .NET controls with the same name, just different numbers appended?
Posted on 2007-11-26
I have 10 controls that have the same exact name, except for the number appendage.
So now I need to create a method that checks each one of these controls ".Text" property for a certain string. Currently I can do this:
if (videoControl1.Text == string)
else if (videoControl2.Text == string)
else if (videoControl3.Text == string)
else if (videoControl4.Text == string)
else if (videoControl5.Text == string)
etc...you get the idea.
What I'm curious to find out is ...if there is a way to do something in a FOR loop that appends the number to the "videoControl" text and then checks the
For future readers coming here by Google/etc....The below code will not compile...it is just an example of what I'm looking for:
So something like:
for (int i = 0;i < 10; i++)
if (videoControl + i.Text = string)
Any input is appreciated. Thanks.