Add new row data to gridview asp.net c#
I make class with this code :
public class Customer
{
public Customer() { }
public Customer(Customer cust)
{
ID = cust.ID;
Name = cust.Name;
FatherName = cust.FatherName;
Email = cust.Email;
}
public int ID { get; set; }
public string Name { get; set; }
public string FatherName { get; set; }
public string Email { get; set; }
}
and create this function to load list with some data:
public List<Customer> Generate_Data()
{
List<Customer> lstCustomer = new List<Customer>();
Customer customer = new Customer();
customer.ID = 1;
customer.Name = "John Cena";
customer.FatherName = "John";
customer.Email = "cena@gmail.com";
lstCustomer.Add(new Customer(customer));
customer.ID = 2;
customer.Name = "Mokesh";
customer.FatherName = "Rajnikant";
customer.Email = "mokesh@gmail.com";
lstCustomer.Add(new Customer(customer));
customer.ID = 3;
customer.Name = "Bilal Ahmad";
customer.FatherName = "Kashif";
customer.Email = "bilal@gmail.com";
lstCustomer.Add(new Customer(customer));
customer.ID = 4;
customer.Name = "Chin Shang";
customer.FatherName = "Shang Woe";
customer.Email = "chinshang@gmail.com";
lstCustomer.Add(new Customer(customer));
return lstCustomer;
}
return this list to bind with grid, code is :
List<Customer> lstCustomer = new List<Customer>();
lstCustomer = Generate_Data();
GridView1.DataSource = lstCustomer;
GridView1.DataBind();
my question are :
I add 4 thextboxes and button to aspx page with name
Id,Name,FatherName,Email
. when click on button, I want add my new values of textboxes to gridview1
row. I want add row to gridview dynamically.
If I define an empty gridview, How can I add my textboxes values to
gridview rows. Is not equal method with question1 ?
No comments:
Post a Comment