Indexing a control

  • Thread starter Thread starter Jim McGivney
  • Start date Start date
J

Jim McGivney

In VB6 I could form an array of labels and reference them by index number.
In a C# ASP.net 2 application I need to reference Label33 through Label64
programmatically. I'd like to use a for loop
for (i = 33; i < 65; i += 1)
Any suggestions on how to accomplish this would be appreciated. Code
samples are welcomed. I'd like the correct syntax.
Thanks in advance for your help,
Jim
 
You can create your own array of labels and initialize it in Form_Load event
handler, or right in the constructor after all the labels are created.

Something like:

private Label[] m_arrLabels;

private void Form_Load( object sender, EventArgs e )
{
m_arrLabels = new Label[3] { Label1, Label2, Label3 };
for( int i = 0; i < m_arrLabels.Length; i ++ )
m_arrLabels.Text = "label " + i;
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Back
Top