How do I bind the WebDataGrid to my business objects?

[Infragistics] Tony Lombardo / Saturday, February 28, 2009

The WebDataGrid can bind to a variety of objects, including an IList which is what we'll use in the example below.

protected void Page_Load(object sender, EventArgs e) 
{ 
    //Assign the DataSource property 
    this.WebDataGrid1.DataSource = this.Customers; 
    //Call DataBind 
    this.WebDataGrid1.DataBind(); 
} 
    //Get a list of customers 
public List<Customer> Customers 
{ 
    get 
    { 
        //For this example, just create a new list and add one item to it 
        //This is where you would return your List of customers which would 
        //ordinarily be cached or saved as a private member 
        List<Customer> _Customers= new List<Customer>();
        _Customers.Add(new Customer(0, "Tony")); 
        return _Customers; 
    } 
} 

//The Customer class 
public class Customer 
{ 
    public Customer(int id, string name) 
    { 
        this.ID = id; this.Name = name; 
    } 
    
    //Use Auto Generated Properties for convenience 
    
    public string Name {get;set; } 
    
    public int ID { get; set; } 
}