Monday 22 July 2013

New Trends in ASP.NET Data Binding

Every ASP.Net web form control inherits the DataBind method from its parent Control class, which gives it an inherent capability to bind data to at least one of its properties. This is known as simple data binding or inline data binding.
Simple data binding involves attaching any collection (item collection) which implements the IEnumerable interface, or the DataSet and DataTable classes to the DataSource property of the control.

The ASP.NET data binding model underwent a significant refresh with version 2.0, mostly due to the introduction of data source controls and data binding expressions. These two families of components provide ASP.NET with a declarative model for data fetching and data manipulation. Data source components force layering and promote a neater separation between presentation and data access, even in relatively simple projects. Data source components offer an alternative to the classic ASP.NET binding model based on a programmatic and explicit binding between enumerable data and the DataSource property of data-bound controls.

Starting with ASP.NET 2.0, all data-bound controls support data source components for fetching, but only a few of them are designed to use data source components for other operations such as insertion, deletion, and update. For example, the GridView control is just a smarter version of the DataGrid control that, among other little things, fully supports the new data binding model. Designed to render tabular data, the GridView is partnered by DetailsView and FormView that render out the content of a single record at a time.
In ASP.NET 3.5, the family of “view” data-bound controls has a new addition – the ListView control. In actual fact, the ListView control fills a gap. There’s no control, in previous versions of ASP.NET, for iterating data templates for all the records in a data source. ASP.NET provides Repeater and DataList controls, but they only support data source components for fetching. The ListView control can be considered as an enhanced version of the DataList control that fully supports data source components.

The ListView combines the layout flexibility of a DataList or Repeater control with the power of two-way data binding of data source controls such as GridView and DetailsView. The ListView control can be used to implement virtually any reporting and publishing scenarios you can imagine. Its distinct layout template gives you total control over the HTML being generated and the style it must have. Various item templates (regular, alternate, edit, selected, insert) let you choose the markup to output for each possible state of the control. Finally, the ListView is pageable using an external pager control – the new DataPager control. ListView and DataPager controls are the only new server controls in ASP.NET 3.5, but they add functionality that was previously missing or implemented in a less than optimal way.