Online Book Reader

Home Category

Programming Microsoft ASP.NET 4 - Dino Esposito [216]

By Root 5767 0
a fixed action property. Subsequently, pages are reentrant and always post to themselves. The behavior of the form can’t be changed because it is crucial to the behavior of ASP.NET, but a different feature—cross-page posting—comes to the rescue to let users post data from one page to another. Cross-page posting is essential when you have legacy pages to integrate in a new application that, for whatever reason, can’t be adapted to a more specific ASP.NET architecture.

Input forms also bring to the table the whole theme of input validation. ASP.NET comes with a stock of native validation controls to cover the basic needs of validation. Validators let you put declarative boundaries around input controls so that any user’s input is filtered and validated both on the client and server. This alone is not sufficient to certify an application as secure, but it is a quantum leap in the right direction.

Finally, in this chapter entirely devoted to getting input data into an ASP.NET server application, we’ve covered wizards—namely, a semi-automatic way of breaking up large forms into smaller pieces served individually to the user, while keeping track of some state. Whether you use the ASP.NET Wizard control or roll your own custom solution, the awareness that splitting large forms into sequential screens gives end users a more pleasant experience is what really matters for ASP.NET developers.

Chapter 10. Data Binding


In matters of style, swim with the current; in matters of principle, stand like a rock.

—Thomas Jefferson

Web applications are, for the most part, just data-driven applications. For this reason, the ability to bind HTML elements such as drop-down lists or tables to structured data is a key feature for any Web development platform. Data binding is the process that retrieves data from a given source and associates it with properties on UI elements. In ASP.NET, a valid target for a data binding operation is a server control, also known as a data-bound control.

Data-bound server controls are not another family of controls; they’re simply server controls that feature a few well-known data-related properties and feed them using a well-known set of collection objects.

In ASP.NET, there are three main categories of data-bound controls: list, iterative, and view controls. As you’ll see in more detail later on, list controls repeat a fixed template for each item found in the data source. Iterative controls are more flexible and let you explicitly define the template to repeat, as well as other templates that directly influence the final layout of the control. Finally, view controls are rich user interface components that provide fixed and data-driven behavior, such as showing a table of records or a single record.

In this chapter, we’ll first review the pillars of data binding in ASP.NET and then proceed to examine the various types of data-bound controls.

Foundation of the Data Binding Model


ASP.NET data binding is built around a few properties that any data-bound control exposes. Page authors can assign collections of data to data-bound controls at any time by setting data binding properties. However, the simple assignment of values to data binding properties is not sufficient to modify the control’s user interface. The actual data binding process starts when the page execution flow executes the method DataBind on the page or a particular control.

For a control, performing a data binding action means updating its internal state to reflect the collection of values assigned to its bindable properties. Finally, when the control renders out its markup, the markup will incorporate any bound data.

What kind of data can you pass on to a data-bound control?

Feasible Data Sources


Many .NET classes can be used as data sources—and not just those that have to do with database content. In ASP.NET, any object that exposes the IEnumerable interface is a valid bindable data source. The IEnumerable interface defines the minimal API necessary to enumerate the contents of the data source:

public interface IEnumerable

Return Main Page Previous Page Next Page

®Online Book Reader