An Introduction to Data Binding

There is a common problem and solution pattern at hand with applications that front databases. Typically, data has to be fetched from the database into the application, and the application’s user interface has to be updated to display the data in an appropriate manner. For large data sets, the concept of paging comes into play. Because it is inefficient to load in, say, a 100MB data set, a paging mechanism needs to be pressed into action to enable the user to move forward and back through the data “stream.” After the data has safely made it into the application’s UI, the application-to-database flow needs to be handled. For any pieces of data that have been changed, those changes have to be reconciled and committed back into the database.

Data binding is the term given to the implementation of a design pattern that handles all facets of this round trip of data from a data structure, into an application’s controls, and back again. Although the data structure is most commonly a database, it could be any sort of container object that holds data, such as an array or a collection. .NET further stratifies the concepts of data binding into simple data binding and complex data binding. Both of these terms refer to a control’s intrinsic capabilities in the larger context of the data-binding process.

Simple Data Binding

Simple data binding is the capability for a control to bind to and display a single data element within a larger data set. A TextBox control is a great example of a control commonly used in simple data-binding scenarios. You might use a TextBox, for example, to display the last name of an employee as it is stored within the employee table of a database.

Support for simple data binding is widespread throughout both the Windows and web forms controls. When you use the built-in capabilities of the Windows and Web Forms Designer, it is trivial to add a group of controls to a form and simple-bind them to a data set (more on this in a bit).

Complex Data Binding

The term complex data binding refers to the capability of a control to display multiple data elements at one time. You can think of this as a “multirow” capability. If a control can be leveraged to view multiple rows of data at one time, it supports complex data binding.

The DataGridView control (for Windows forms) and DataGrid control (for web forms) are premier examples of controls that were purpose-built to handle tabular (multirow and multicolumn) data.

Although the internals necessary to implement data binding are messy, complex, and hard to understand, for the most part the Visual Studio tools have abstracted the cost of implementing data binding out to a nice and easy drag-and-drop model. Now let’s look at how to rapidly build out support for round-trip data binding.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset