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(object sender, System.EventArgs e)
{
if(!(ViewState["Addresses"]==null))
{
this.addresses = (ArrayList)ViewState["Addresses"];
}
else
{
this.addresses = new ArrayList();
}
}
private void Button1_Click(object sender, System.EventArgs e)
{
//add addresses to the arraylist
if(this.TextBox1.Text.Length > 0)
{
addresses.Add(this.TextBox1.Text.ToString()+","+
this.TextBox2.Text.ToString() + ", " + this.TextBox3.Text.ToString() +
","+this.TextBox4.Text.ToString() + ", " + this.TextBox5.Text.ToString() + ",
" + this.TextBox6.Text.ToString()); }
//Clear the Address items textboxes
this.TextBox1.Text = "";
this.TextBox2.Text = "";
this.TextBox3.Text = "";
this.TextBox4.Text = "";
this.TextBox5.Text = "";
this.TextBox6.Text = "";
//display the search addresses in the label
IEnumerator enumerator = addresses.GetEnumerator();
System.Text.StringBuilder buffer = new System.Text.StringBuilder();
while (enumerator.MoveNext() )
buffer.Append(enumerator.Current + "\n" );
Label1.Text = buffer.ToString();
//Loop through to display what we are searching on
System.Text.StringBuilder _oOutput = new System.Text.StringBuilder();
for(int i = 0; i < addresses.Count; i++)
{
_oOutput.Append((string)addresses[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.Text = _oOutput.ToString();
}
Here is the asp table I have in the html code: -
<asp:table id="tblSearchAddresses" Width="100%" BackColor="#00C0C0"
BorderColor="Yellow" Runat="server">
<asp:TableRow>
<asp:TableCell>
<asp:Label runat="server" ID="lblAddress1"></asp:Label>
</asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell>
<asp:Label runat="server" ID="lblAddress2"></asp:Label>
</asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell>
<asp:Label runat="server" ID="lblAddress3"></asp:Label>
</asp:TableCell>
</asp:TableRow>
etc.......
</asp:table>