Variables numeradas

12/06/2008 - 12:54 por luAnimeDes | Informe spam
Buenas mi duda es la siguiente,
es posible tener varios TextBox y acceder a ellos mediante un indice??

p.e.
tenemos 4 textBox y los nombramos texBox_1, texBox_2, texBox_3 y
texBox_4.

podemos hacer referencia a ellos de una forma parecida a :

for (int i=1; i<=4; i++) {
if ( texBox_i.Text == "2" ){
texBox_i.Text="";
}
}
 

Leer las respuestas

#1 Miquel
12/06/2008 - 13:06 | Informe spam
Hola,

Un posible solución:

for (int = 1; i <= 4; i++)
{
TextBox t = (TextBox)Controls["texBox" + i.ToString()];
if (t.Text == "2")
t.Text = "";
}

Saludos



escribió en el mensaje de noticias
news:
Buenas mi duda es la siguiente,
es posible tener varios TextBox y acceder a ellos mediante un indice??

p.e.
tenemos 4 textBox y los nombramos texBox_1, texBox_2, texBox_3 y
texBox_4.

podemos hacer referencia a ellos de una forma parecida a :

for (int i=1; i<=4; i++) {
if ( texBox_i.Text == "2" ){
texBox_i.Text="";
}
}

Preguntas similares