Monday, February 13, 2012

A datatable with columns at run time


01 public class Customer
02    {
03        private string _firstName;
04        private string _lastName;
05        private string _email;
06 
07        public string FirstName
08        {
09            get { return _firstName; }
10            set { _firstName = value; }
11        }
12 
13        public string LastName
14        {
15            get { return _lastName; }
16            set { _lastName = value; }
17        }
18 
19        public string FullName
20        {
21            get { return _firstName + " " + _lastName; }
22        }
23 
24        public string Email
25        {
26            get { return _email; }
27            set { _email = value; }
28        }
29      }








------------------------------------------------
 //DataGrid1.DataSource=GetCustomers();
// DataGrid1.DataBind();
DataTable dt=new DataTable();
dt=GetCustomers();
-------------------------------------------------
09        private List<Customer> GetCustomers()
10        {
11            List<Customer> customers = new List<Customer>();
12 
13            for (int i = 1; i <= 20; i++)
14            {
15                Customer customer = new Customer();
16                customer.FirstName = "FirstName" + i;
17                customer.LastName = "LastName" + i;
18                customer.Email = "Email" + i;
19                customers.Add(customer);
20            }
21 
22            return customers;
23        }







No comments:

Post a Comment