mellenburg
Programmer
I have a form that is capturing information from a user. In this example, the user is entering a list of first names. The number of first names entered can be 1 to whatever. I have code that will capture the entry and store it in an array. However, I can't capture the second entry without it overwriting the first. How can I let the user keep clicking the submit button and record all the first names they have entered? Here's the code I have currently.
Code:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
namespace TravelSystem
{
public class TAForm : System.Web.UI.Page
{
protected System.Web.UI.WebControls.DataList dlTravelers;
protected System.Web.UI.WebControls.Label lblFirstName;
protected System.Web.UI.WebControls.TextBox txtFirstName;
protected System.Web.UI.WebControls.RequiredFieldValidator rfvFirstName;
protected System.Web.UI.WebControls.Label lblLastName;
protected System.Web.UI.WebControls.TextBox txtLastName;
protected System.Web.UI.WebControls.RequiredFieldValidator rfvLastName;
protected System.Web.UI.WebControls.Button btnAddTraveler;
protected System.Data.DataSet dsTravelers;
protected ArrayList arrFirstName = new ArrayList();
private void Page_Load(object sender, System.EventArgs e)
{
if (!IsPostBack)
{
}
}
public void btnAddTraveler_Click(object sender, System.EventArgs e)
{
arrFirstName.Add(txtFirstName.Text.ToString());
foreach(string strFirstName in arrFirstName)
{
Response.Write(strFirstName);
}
dlTravelers.DataSource=arrFirstName;
dlTravelers.DataBind();
}
}
}