|
|
|
|
|
Data Binding
Binding data to the grid has been simplified to a single line of code. The grid supports all kinds of "lists" from IList to Data Source Control derived types. The grid automatically discovers the schema of the datasource at runtime, including the relationships setup between tables in a datasource and renders the grid contents automatically. The grid's schema can be altered to hide columns and include unbound columns. The default setting pulls all the records to the server irrespective of the number of records displayed on the page. Alternatively, you can use the Pass Through Grouping feature to selectively query records from the datasource based on the grid's current view.
|
|
|
|
The Grid Grouping Control offers varied data binding options. It provides built-in support for numerous datasources which are listed below:
-
DataTable
-
DataSet
-
DataView
-
XML Data
-
Custom
The Custom collection option enables the implementation of interfaces such as, IList, ITypedList and IBindingList among others.
Binding to ADO.NET DataSet
The Grid Grouping Control can be bound to any ADO.NET dataset with its varied data binding options. Assigning the required dataset to the Grid Grouping Control's DataSource option will bind the grid to the datasource. The grid will automatically extract the field information from the bound columns and also any relationships between multiple tables in the datasource to render hierarchical data.
Set up ADO.NET Data
Grid bound to an ADO.NET Dataset
Binding to XML Data
The Grouping Grid provides support for XML datasources. It can be bound to such datasources in Design Time.
Set up XML Datasource
XML Grid
Binding to an ArrayList
The Grouping Grid can be bound to any collection that derives from IList. ArrayList, for example, implements the IList interface. Once an arraylist is created and is populated with a list of items, it can be bound to the grid by using the Datasource option. The Grid will use reflection to identify the public properties exposed by the items and determine the columns that are to be rendered.
Build an ArrayList and bind it to the Grid
|
|
|
|
Grid Grouping Control provides built-in support for display of hierarchical relationships. Such relationship can either be defined in
the dataset or manually set up between multiple tables. If the hierarchical relationships are defined in the dataset then the
grid will automatically identify and display them.
The records involved in these hierarchical relationships can be synchronized to update changes in all records whenever changes are made to one record. The parent records are expandable and collapsible. All records with nested relations can be expanded to reveal the underlying detailed record, which can be achieved by clicking on the plus/minus buttons.
The example below, shows a grouping grid that is bound to a hierarchical dataset comprising of 3 tables inter-connected by a
master-detail relationship.
Hierarchical Grid
|
|
|
|
The foreign key constraints defined in the database will be in effective in Grid Grouping Control when the grid is bound to the DataSet. This prevents the deletion of a table entry referenced in another table. Furthermore, when editing a foreign key field the acceptable values are made available in a Combo box.
Grid with Foreign Key Constraint
|
|
|
|
Grid Grouping Control provides built-in support for data caching. The need for querying the datasource for every postback and callback roundtrip is eliminated, thus enhancing grid performance and minimizing load time. Two supported caching modes are listed below:
-
View State - The datasource object will be serialized and added to view state.
-
Session - The datasource object is added to session.
-
None - This mode turns off data caching and the datasource must be initialized for every postback and callback.
|
|
|
|
When bound to valid datasources, the grid determines the bound columns' schema by looking up the column types in the underlying data sources. When bound to custom lists the grid uses reflection to look up public types in objects in the list.
A custom class named 'MyClass' and its public property definitions are illustrated below.
Public Properties in 'MyClass' Implementation
The resultant grid bound to the above collection is shown below.
Notice that the grid columns are constructed based on the public properties of the custom class.
Grouping Grid Bound to a Custom Collection
|
|
|
|
Pass Through Grouping is a great way to limit the data being retrieved from the datasource. The grid's default setting pulls all the records in the underlying datasource to be enable effective grouping and summarizing. However, you can override this behavior using Pass Through Grouping and retrieve only the required records from the data source. Typically,these are the records required to display the current page. The grid could be bound to millions of records. By using Pass Through Grouping, desired number of records may be retrieved from the datasource based on page size.
Pass Through Grouping can be implemented on any datasource using any data retrieval technique. However, this method is ideally suited to retrieve data through LINQ. Pass Through Grouping using the LINQ data retrieval technique is elaborated in the next section.
Pass Through Grouping
|
|
|
|
The LINQ method is great to retrieve data from datasources. LINQ lets you build intuitive query expressions in a language of your choice with optional support for transforming, projecting or shaping the data into many different forms before it gets displayed on the User Interface(UI). For more information on LINQ, see http://msdn.microsoft.com/en-us/netframework/aa904594.aspx.
The Grid now supports binding to LINQ through the Pass Through Grouping feature introduced in the previous section. Binding the grid using LINQ has many advantages. When binding a datasource to the grid without using LINQ, the grid will retrieve all records from the bound datasource to the server, though only few are displayed on the page. This could become a serious overhead while dealing with large datasources. This may be resolved by binding the grid to the LINQ query results instead of the datasource directly. Thus, data from the datasource is retrieved on demand, upon user request(for example,by expanding a collapsed group).
Note that LINQ queries often return anonymous types. Anonymous types are a convenient language feature of Microsoft Visual C# and Microsoft Visual Basic that enable developers to concisely define inline CLR(Common Language Runtime) types within code, without having to explicitly define a formal class declaration of the type.
Since Anonymous types are compiler generated typed objects, the grid cannot serialize it with default formatters (Binary/XML). So, LINQ query results cannot be saved in the ViewState and can only be saved in the session.
|
|
|
|
|
|
|
|