for dynamic allocation of a list of objects you need to use either generics or ArrayList
if we used generics plus session to maintain the value between postbacks the code beside would be something like:
using System.Collections.Generic;
using System;
using System.Text;
public partial class _Default : System.Web.UI.Page
{
private List<string> ResultArray
{
get
{
if (Session["resultArray"] == null)
Session["resultArray"] = new List<string>();
return (List<string>)Session["resultArray"];
}
}
protected void btnAdd_Click(object sender, EventArgs e)
{
ResultArray.Add(txtNewText.Text);
txtNewText.Text = string.Empty;
}
protected void btnShow_Click(object sender, EventArgs e)
{
StringBuilder sb = new StringBuilder();
foreach (string s in ResultArray)
{
sb.Append("<br />" + s);
}
lblResultingText.Text = sb.ToString();
}
}
of course I don't recommend using session between post backs to the same page, rather, I recommend adding the strings to a comma separated string and storing it in the view state.
<%= Eyad.Salamin %><aspForums:DontForget>Don't forget to click on Mark as answer on the post that helped you.
This credits that member, earns you a point and marks your thread as Resolved so we will all know you have been helped.
</aspForums:DontForget>