You will need to save your collection during postback. Depending on how large your collection is, you might consider storing it in viewstate, session, etc.
List<Customer> lstCustomer = new List<Customer>(); lstCustomer = Generate_Data(); ViewState["Customers"] = lstCustomer; GridView1.DataSource = lstCustomer; GridView1.DataBind();
Therefore, when a user fills in text fields with data and initiates a postback, you can create a new client object and add it to an existing collection. Then reinstall the data into the grid.
Customer customer = new Customer(){ID=int.Parse(TextBox1.Text), Name = TextBox2.Text, FatherName = TextBox2.Text, Email = TextBox2.Text } var lstCustomer = ViewState["Customers"] as List<Customers>; lstCustomer.Add(customer);
Note that you need to add the [Serializable] attribute to the Customer class.
sidprasher
source share