The Unbound mode enables developers to set the object relations definitions and object types information externally, without requires any changes to the business object's sources.
Although it is more convenient to use Inbound mode where you can fully control the behavior of the objects by using provided Attributes, Unbound mode allows external entities to be displayed properly in WebGrid.NET by using the same concepts.
To set the object relations definitions, use the SetObjectRelations method provided by WebGrid.
The SetObjectRelations method must be called in PreInitialize event in order for the Hierarchical Collection to work properly. |
Following is the sample to use SetObjectRelations method.
C# | Copy Code |
protected void WebGrid1_PreInitialize(object sender, System.EventArgs e) { // assign OnPreInitialize event in ASPX // defines the Object Relations ArrayList objectRelations = new ArrayList(); objectRelations.Add(new WebGridObjectRelation( typeof(CustomerCollection), "CustomerID", "Orders", typeof(OrderCollection), "CustomerID")); objectRelations.Add(new WebGridObjectRelation( typeof(OrderCollection), "OrderID", "OrderDetails", typeof(OrderDetailCollection), "OrderID")); // defines the Parent and Child Type information // objectTypes contains 3 object array: The parent collection type, // child item type, the primary keys of child collection // Primary keys can be string (if only 1 primary key defined), // or array of string for multiple primary keys scenario. ArrayList objectTypes = new ArrayList(); objectTypes.Add(new object[] { typeof(CustomerCollection), typeof(Customer), "CustomerID"}); objectTypes.Add(new object[] { typeof(OrderCollection), typeof(Order), "OrderID"}); objectTypes.Add(new object[] { typeof(OrderDetailCollection), typeof(OrderDetail), new string[] { "OrderID", "ProductID"}}); // assign the required definitions through SetObjectRelations method // the SetObjectRelations need to be called in new PreInitialize method // since it needs to be initialized in earliest phase. WebGrid1.SetObjectRelations(objectRelations, objectTypes); } |
The ObjectRelations definition used the same concept as in Inbound Mode, that is by constructing WebGridObjectRelation and add it to an instantiated ArrayList.
The ObjectTypes parameter holds information about the type of the ParentCollection, the type of the Item, and the primary keys existed in the Item. To clearly understand the terms of the ObjectTypes concept, see following Northwind's Customer Table illustration:
-
ParentCollection
CustomerCollection Type, a collection which contains all Item of type Customer.
-
Item/ChildObject
Customer Type, the Type contained in ParentCollection.
-
PrimaryKeys
CustomerID, this is a public property available within the Customer Type.
-
The tutorial for Outbound mode is available in Tutorial Solution >> V4.0 >> Hierarchical_Binding_Outbound.aspx
Overview
Getting Started
WebGrid Features Overview
Other Resources
Walkthrough Topics
How-to Topics