I have created two TextBoxes to enter the FirstName and LastName of an employee in a web-based ASP.NET application using C# on Visual studio 2010. There is a Button. when I click on it, the values that I enter in the TextBoxes should be displayed in a Gridview without those values being stored in the database. I have already implemented it using ArrayList as shown below. But now I want to implement it using Generic List (Typed List). How can I do that? Can you provide a sample code to execute the above mentioned functionality?
How can I tweak the code given below, to implement the functionality using Generic List (Typed List)?
**
protected void btnTextDisplay_Click(object sender, EventArgs e)
{
ArrayList arr;
if (Session["array"] == null)
{
arr = new ArrayList();
}
else
{
arr = (ArrayList)Session["array"];
}
arr.Add(txtName.Text + "," + txtCity.Text); //store textbox values in the array list
Session["array"] = arr;
DataTable dt = new DataTable();
dt.Columns.Add("Name");
dt.Columns.Add("City");
for (int i = 0; i < arr.Count; i++)
{
string[] arrVal;
arrVal = arr[i].ToString().Split(',');
dt.Rows.Add(arrVal[0], arrVal[1]);
}
gvDisplay.DataSource = dt;
gvDisplay.DataBind();
}
**