WebGrid supports a number of ways to bind data from the database to the control. One of the most common ways to bind data to WebGrid is through the datasource controls which are introduced in latter version of ASP.NET. The datasource controls allow you to bind data in declarative manner, without requiring you to write a single line of code.
This topic contains the following sections:
Introduction
Codeless data binding means that you can configure the DataSource, its connection and its related property without writing codes. In other words, you can quickly configure the WebGrid to connect to a DataSource by simply using drag, drop and click. Declaratively, you can create a WebGrid instance and bind it to a table in your SQL database in two simple statements as in the following:
Code | Copy Code |
---|---|
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<$ ConnectionStrings:SqlConnectionString >" SelectCommand="SELECT * FROM [Tasks]"> </asp:SqlDataSource> <ISWebGrid:WebGrid ID="WebGrid1" runat="server" DataSourceID="SqlDataSource1" Height="300px" HorizontalAlign="NotSet" Width="100%"> </ISWebGrid:WebGrid> |
With this new data binding concept, programming databind web application is very easy, simple and straightforward. Also, notice that there are no codes required in the page's code behind. In previous version, you will need to configure InitializeDataSource event and write codes inside the event which pass the DataSource to e.DataSource. That is no longer needed in WebGrid version 5.0, although the old data binding mechanism is still supported for backward compatibility. |
- Basic DataSourceControl support
- Advanced DataSourceControl support
Basic DataSourceControl support
- AccessDataSource
- SqlDataSource
- ObjectDataSource
Three of the DataSource controls above support single table view and thus can only be used as flat configuration in WebGrid control.
Advanced DataSourceControl support
In addition to basic DataSource controls, WebGrid is designed to handle more advanced DataSource controls for enterprise development needs. The advanced DataSource controls supported are:
- XMLDataSource
- IntersoftDataSource
XMLDataSource control is a DataSource control designed to retrieve data from XML source. WebGrid control implements a special support for XMLDataSource so that it can read the XML source defined in the XMLDataSource and display it in a tree-like layout.
Note that the XMLDataSource control supported in WebGrid is a lightweight implementation that designed to simulate a TreeView control and thus can be used only for basic display purpose. For more advanced features of TreeView control, please refer to Intersoft's WebTreeView control. |
- Since that WebGrid utilizes its Hierarchical and ChildTable feature to simulate a tree-like display, WebGrid can effectively process structured XML only. Please avoid non-structured XML source as they will not be properly handled.
- While operating in tree-like display, most Grid-specific features will be disabled such as column sorting, filtering, load more data, paging, etc.
- Other advanced layout features are not supported and should be disabled since they are irrelevant to the TreeView function, such as ColumnSet layout, self referencing, preview row, etc.
- The only functional feature in this mode is Grouping feature. The grouping feature enables you to group a hidden column available in the XML source. For instance, take a look at the following illustration.
To bind to a XmlDataSource control, WebGrid comes with full design-time support that allows you to easily configure the data binding. To learn more about design-time support for XMLDataSource, please refer to Design-time support: XML DataSource control.
The other advanced DataSource control supported by WebGrid is hierarchical (multi table views) DataSource control that enables you to easily connect the WebGrid control to a relational dataset available in your web application without any codes.
The hierarchical DataSource control named ISDataSource is exclusively developed by Intersoft Solutions to support the hierarchical feature of WebGrid while conforming the DataSource control architecture offered in ASP.NET 2.0. |
About ISDataSource Licensing in WebGrid
Intersoft DataSource Control, also known as ISDataSource, is sold as standalone component product that requires its own runtime license key. However, since ISDataSource plays a very important role in WebGrid's data access functionality, ISDataSource is provided at no additional cost when used together with WebGrid.
When ISDataSource detects a valid license of WebGrid in a web application, it will automatically functioning as licensed version. In this case, you are not required to set the runtime license key for ISDataSource in the application's web.config.
If you would like to use ISDataSource in a web application that does not contain WebGrid (also known as standalone mode), you would need a separate license to use ISDataSource. There are numerous standalone scenarios where ISDataSource is best used:
- Using ISDataSource for WebCombo.NET 4.0's load on demand binding.
- Using ISDataSource to replace multiple instances of ObjectDataSource in a web page.
- Using ISDataSource to take advantage of its advanced caching capabilities, such as file server caching and flexible caching setting.
- Using ISDataSource as the fundamental DataSource control for all data binding purposes. With powerful features such as automatic conflict detection, rich designers, custom object support and advanced load on demand support - it is worth to consider using ISDataSource as the main DataSource control in web application development.
The Benefits of the DataSource Control Binding
Here are the benefits of the new DataSource control binding support:
- Improved developer's productivity via codeless, simple and hassle-free data binding.
- Cleaner separation between User Interface and Data Access/Business Layer codes
All data layer codes and logics are now handled at DataSource control level instead of component level. That means UI component such as WebGrid is now purely serving as data grid and visualization function, and no longer handling DataSource. - Better architecture
For more than decades, developer was struggling to find the best pattern in developing databound application. DataSource control binding concept is one of the most appealing and acceptable mechanism recognizing its cleaner separation between user interface and data access layer. - Highly reusable
DataSource control offers better reusability since it has rock solid architecture. For instance, developer can write business layer codes in application level which is used throughout the application and use ObjectDataSource to connect to the business layer function. - Extensible
DataSource controls such as ObjectDataSource and ISDataSource (Intersoft's proprietary multi-views DataSource control) have the ability to connect to custom business layer codes. You can also connect the controls to DataSet and TableAdapter that generated using Visual Designer in Visual Studio 2005, as well as connect it to extended function that you write in an extended class through new "partial class" mechanism.
Several important notes that developer should aware with the new DataSource control concept:
- InitializeDataSource event is no longer fired when the WebGrid is bound to DataSourceID. This event will still be fired normally when the DataSourceID property is empty (old data binding mode).
- You cannot bind to DataSource control and DataSource object at the same time. For instance, if you set DataSourceID to SqlDataSource1 and at the same time set WebGrid1.DataSource = dsNorthWind.Customers in the code, this will throw an invalid operation exception.
- All internal operations and existing functions in WebGrid are still working properly with the new DataSource control binding such as column sorting, filtering, grouping, etc. This ensures full compatibility in behaviors and functions with the previous versions.
- When the DataSource control is configured for updating capabilities such as add new record, update record and delete record - WebGrid can automatically communicate to the assigned DataSource control for its data manipulation process without any codes at the Grid level. In previous versions, developers are required to write their own codes to process the updates to physical database. For more information, refer to Walkthrough: Configuring updatable WebGrid bound to ObjectDataSource control
- Data caching
In pre-2007 platform, Intersoft's databound control such as WebCombo.NET and WebGrid employ built-in automatic data caching mechanism. In 2007 product lines, the built-in data caching is no longer functioning when the control is bound to DataSource control. To configure data caching, please refer to the capability of the DataSource control that you used to bound to the control. For instance, if you bind a WebGrid control to SqlDataSource, then you can enable the caching by setting EnableCaching of the SqlDataSource control to True.
Getting Started
Getting Started
Overview
WebGrid Features Overview
Other Resources
Walkthrough Topics
How-to Topics
FAQ: Can I perform retrieve structure programmatically when bound to DataSource control?