[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Christophe Sauvage

1/3/2003 12:10:00 AM

Can we call a control dynamically ?

for exemple :

we can do this code :

texbox_1.Text = "1";
texbox_2.Text = "2";
texbox_3.Text = "3";
texbox_4.Text = "4";
texbox_5.Text = "5";

But i want to make a code like this :

for (int i = 1; i <= 5; i++) {
("texbox" + i ).Text = "Truc " + i;
}

There is a way to do that ?


Christophe.







3 Answers

Kim Bach Petersen

1/3/2003 12:46:00 AM

0

> There is a way to do that ?

Simply make an array of textboxes (or other controls):

Dim TextBoxes(5) As TextBox

The textboxes can now be added dynamically (Page.Controls.Add) or read into
the array using FindControl if they are predefined.

Kim :o)


christophe

1/3/2003 10:27:00 AM

0

Thanks for replying.


Here is the good code :

void ManipulateTexbox1(Object sender, EventArgs e) {

TextBox[] TextBoxArray = new TextBox[3] { txtBox_1, txtBox_2,
txtBox_3 };

for (int i = 0; i < 3; i++){
ManipulateTexbox2(TextBoxArray[i]);
}
}

void ManipulateTexbox2 (TextBox txtB){
txtB.Text = "lorem" ;
}

"Kim Bach Petersen" <msnews@kensho.dk> wrote in message
news:uOfYWkrsCHA.968@TK2MSFTNGP12...
> > There is a way to do that ?
>
> Simply make an array of textboxes (or other controls):
>
> Dim TextBoxes(5) As TextBox
>
> The textboxes can now be added dynamically (Page.Controls.Add) or read
into
> the array using FindControl if they are predefined.
>
> Kim :o)
>
>


Newz

1/4/2003 11:21:00 AM

0

You could also do it this way and avoid creating the array.

for (int i = 1;i <= 3; i++)
ManipulateTextBox2(((TextBox)this.FindControl("txtBox_" +
i.ToString())));

"christophe" <csauvage@agenc-i.com> wrote in message
news:#95MKpwsCHA.584@TK2MSFTNGP09...
> Thanks for replying.
>
>
> Here is the good code :
>
> void ManipulateTexbox1(Object sender, EventArgs e) {
>
> TextBox[] TextBoxArray = new TextBox[3] { txtBox_1, txtBox_2,
> txtBox_3 };
>
> for (int i = 0; i < 3; i++){
> ManipulateTexbox2(TextBoxArray[i]);
> }
> }
>
> void ManipulateTexbox2 (TextBox txtB){
> txtB.Text = "lorem" ;
> }
>
> "Kim Bach Petersen" <msnews@kensho.dk> wrote in message
> news:uOfYWkrsCHA.968@TK2MSFTNGP12...
> > > There is a way to do that ?
> >
> > Simply make an array of textboxes (or other controls):
> >
> > Dim TextBoxes(5) As TextBox
> >
> > The textboxes can now be added dynamically (Page.Controls.Add) or read
> into
> > the array using FindControl if they are predefined.
> >
> > Kim :o)
> >
> >
>
>