Flat Collection data binding has been introduced since Version 3.5 of WebGrid.NET Enterprise. Along with the addition of Hierarchical Collection binding support in V4.0, there are multiple ways to display flat collection in V5.0.
There are two methods on how V5.0 handles Flat Collection:
-
Direct binding
This is the flat collection implementation used in V3.5. Direct binding does not require additional implementation of interfaces or attributes to existing collections, although it still has many limitations and scoped for basic scenarios.
This traditional method is provided for backward compatibility purpose in V5.0.
The tutorial for Direct Binding is available in Tutorials Solution >> V3.1 >> BindingIList.aspx
When a collection does not implement IHierarchicalList interface, WebGrid.NET will automatically use this Direct binding method to handle Flat collection. -
IHierarchicalList implementation
V5.0 introduces a more powerful collection handling which is originally designed for Hierarchical Collection. This new implementation overcomes many limitations over the traditional implementation, such as the usage of Attributes to easily control the Table's Name, Column's Caption and Visibility of a public property and more.
Due to broad scenarios support of hierarchical collections, the final version of 4.0 has opened the support to use similar implementation for Flat Collection. To use the new implementation for Flat collection, you only need to implement the
IHierarchicalList interface.Hierarchical property of the LayoutSettings is required to be set to False for Flat Collection support using new implementation. Sample code for IHierarchicalList implementation for Flat Collection:
C# Copy Code public class CustomerCollection : System.Collections.CollectionBase, IHierarchicalList { public void Add(Customer aCustomer) { aCustomer.Owner = this; List.Add(aCustomer); } public bool Remove(int index) { // Check to see if there is a customer at the supplied index. if (index > Count - 1 || index < 0) { return false; } else { List.RemoveAt(index); return true; } } public void Remove(Customer cust) { List.Remove(cust); } public Customer Item(int Index) { return (Customer) List[Index]; } public Customer FindByID(string customerID) { foreach (Customer c in this.InnerList) { if (c.CustomerID == customerID) return c; } return null; } #region IHierarchicalList Members public Type ItemType { get { return typeof(Customer); } } #endregion }
Sample code for data binding:
C# Copy Code private void WebGrid1_InitializeDataSource(object sender, ISNet.WebUI.WebGrid.DataSourceEventArgs e) { CustomerCollection customers = DataLayer.GetCustomers(); // populate order to all customers foreach (Customer cust in customers) { cust.PopulateOrders(); } e.DataSource = customers; }
Overview
Getting Started
WebGrid Features Overview
Other Resources
Walkthrough Topics
How-to Topics