Intersoft WebGrid Documentation
Unbound Mode
See Also Send comments on this topic.
Intersoft WebGrid > Learning More > Working with Collection DataBinding > Hierarchical Collection > Unbound Mode

Glossary Item Box

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# CopyHover ImageCopy 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:

See Also

©2012 Intersoft Solutions Corp. All Rights Reserved.