Adding Arraylist Items to an asp table. Please help me

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

    #1

    Adding Arraylist Items to an asp table. Please help me

    I have been getting on well with help from this forum trying to create an
    array list and work with it. Everything is working fine apart from
    displaying my array list items into the labels in my asp table.
    The asp table has numerous rows and each row has a label item within it.
    Im finding it impossible to get something to work which adds the newest item
    in the array list to the next row in the asp table. the first time the
    button is clicked I want the array item added to the asp table and all
    preceeding clicks id like the rows underneath added with the next array
    value.
    Sorry finding this hard to explain but hope you know what I mean.

    Below might give you an idea of what im looking for. On the first click id
    like the arraylist value added to the asp table like so

    Table Addresses(asp table)
    11 Add, 11 City, 11Postcode

    On the next click id like the 2nd element of the array to be added like so

    Table Addresses(asp table)
    11 Add, 11 City, 11 Postcode
    22 Add, 22 City, 22 Postcode

    etc, etc

    So Im basically looking to display each item of the Array one by one
    underneath each other in the asptable.

    Is anyone able to help me with this?? im going crazy trying to work it out!!
    Thanks in advance for anyone that can help me further with this problem.

    The CODE I HAVE TO DATE ARE AS FOLLOWS: Code behind page

    private ArrayList addresses;

    private void Page_Load(objec t sender, System.EventArg s e)
    {
    if(!(ViewState["Addresses"]==null))
    {
    this.addresses = (ArrayList)View State["Addresses"];
    }
    else
    {
    this.addresses = new ArrayList();
    }
    }


    private void Button1_Click(o bject sender, System.EventArg s e)
    {
    //add addresses to the arraylist
    if(this.TextBox 1.Text.Length > 0)
    {
    addresses.Add(t his.TextBox1.Te xt.ToString()+" ,"+
    this.TextBox2.T ext.ToString() + ", " + this.TextBox3.T ext.ToString() +
    ","+this.TextBo x4.Text.ToStrin g() + ", " + this.TextBox5.T ext.ToString() + ",
    " + this.TextBox6.T ext.ToString()) ; }

    //Clear the Address items textboxes
    this.TextBox1.T ext = "";
    this.TextBox2.T ext = "";
    this.TextBox3.T ext = "";
    this.TextBox4.T ext = "";
    this.TextBox5.T ext = "";
    this.TextBox6.T ext = "";

    //display the search addresses in the label
    IEnumerator enumerator = addresses.GetEn umerator();
    System.Text.Str ingBuilder buffer = new System.Text.Str ingBuilder();
    while (enumerator.Mov eNext() )
    buffer.Append(e numerator.Curre nt + "\n" );
    Label1.Text = buffer.ToString ();

    //Loop through to display what we are searching on
    System.Text.Str ingBuilder _oOutput = new System.Text.Str ingBuilder();
    for(int i = 0; i < addresses.Count ; i++)
    {
    _oOutput.Append ((string)addres ses[i]);
    _oOutput.Append ("\n");
    }
    // ******would like to be able to loop through the addresses added to the
    array list and populate the labels in my asp table. The code for me asp
    table is below*********
    //lblAddress1.Tex t = _oOutput.ToStri ng();
    }

    Here is the asp table I have in the html code: -
    <asp:table id="tblSearchAd dresses" Width="100%" BackColor="#00C 0C0"
    BorderColor="Ye llow" Runat="server">
    <asp:TableRow >
    <asp:TableCel l>
    <asp:Label runat="server" ID="lblAddress1 "></asp:Label>
    </asp:TableCell>
    </asp:TableRow>
    <asp:TableRow >
    <asp:TableCel l>
    <asp:Label runat="server" ID="lblAddress2 "></asp:Label>
    </asp:TableCell>
    </asp:TableRow>
    <asp:TableRow >
    <asp:TableCel l>
    <asp:Label runat="server" ID="lblAddress3 "></asp:Label>
    </asp:TableCell>
    </asp:TableRow>
    etc.......
    </asp:table>
Working...