short question1

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • josema

    short question1

    Hi...
    I have an array of elements that has dinamic size,
    sometimes has 5 elements, sometimes 3 etc...
    I would like to create a WebForm with as <input type=text>
    as elements i have in this array
    What is the way to make this, cause if i use a loop i dont
    know how i can instanciate the class with another name...
    For instance

    for (int i=0;i<array.len ght;i++)
    {
    TextBox mytextbox=new TextBox();
    }
    the problem with this is that: mytextbox is instanciate so
    many times and i dont know how i can give another name to
    the control in each round in the loop.
    I suppose that its not the correct way, make this.. no?
    Thanks in advance...
    Josema.

  • Morten Wennevik

    #2
    Re: short question1

    On Wed, 12 Nov 2003 02:58:41 -0800, josema <jestradeREMOVE THIS@ocu.org>
    wrote:
    [color=blue]
    > Hi...
    > I have an array of elements that has dinamic size,
    > sometimes has 5 elements, sometimes 3 etc...
    > I would like to create a WebForm with as <input type=text>
    > as elements i have in this array
    > What is the way to make this, cause if i use a loop i dont
    > know how i can instanciate the class with another name...
    > For instance
    >
    > for (int i=0;i<array.len ght;i++)
    > {
    > TextBox mytextbox=new TextBox();
    > }
    > the problem with this is that: mytextbox is instanciate so
    > many times and i dont know how i can give another name to
    > the control in each round in the loop.
    > I suppose that its not the correct way, make this.. no?
    > Thanks in advance...
    > Josema.
    >[/color]

    You don't have to worry about what name each texbox have as they don't
    care. But you do need to keep track of the references to them. In your
    loop, you will create a new TextBox but it will disappear instantly since
    you don't store the reference for it anywhere.

    I'm not sure what you are trying to accomplish, but a way to create as
    many textboxes as there are items in the array list you can do something
    like

    ArrayList textboxList = new ArrayList();
    for( int i = 0; i < array.Length; i++ )
    {
    TextBox namemdoesnotmat ter = new TextBox();
    textboxList.Add (namedoesnotmat ter);
    }

    textboxList now holds all TextBox references for later use.

    --
    Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/

    Comment

    Working...