I am trying to add elements from a textbox on a button click to a grid view. Every time the user hits the button, I want it to add on another element to the end.
Currently, the [0] element gets overridden each time the button is clicked and displays only the most recently added string value. I am also trying to add the arraylist to a session variable.
How can this be done better?
public string InputArray;
ArrayList myArrayList = new ArrayList();
private void BindData()
{
SuffixGridView.DataSource = myArrayList;
SuffixGridView.DataBind();
}
protected void Page_Load(object sender, EventArgs e)
{
InputArray = suffixTextBox.Text;
Session["postFix"] = (ArrayList)myArrayList;
}
protected void SuffixButton_Click(object sender, EventArgs e)
{
myArrayList.Add(InputArray);
BindData();
suffixTextBox.Text = String.Empty;
}
Page_LoadoverridesSession["postFix"]with the current myArrayList every time — even onSuffixButton_Click(or rather onPage.IsPostBack). Instead, load myArrayList from Session on postback.