The IEnumerable interface defines the minimal API (i.e., the interface with the smallest number of members) to enumerate the contents of a data source, as in The IEnumerable interface represents the lowest-level binding interface.In the real world, you’ll be using more specific classes that can enumerate their content through the IEnumerable interface or richer interfaces derived from IEnumerable, such as ICollection and IList.In other words, you need to bind to a list data bound control.
There are quite a few data source controls available. NET, you can use a variety of classes as data sources.
You aren’t limited to classes that deal with database content, such as Data Reader or Data Table. NET, any object that exposes the IEnumerable interface is a valid bindable data source.
Web Figure 2: Results from the code in Listing 4 The Drop Down List control gets the data to display through either the Data Source or Data Source ID property.
In Listing 4, it gets data through the Data Source property of the Object Data Source control. This object is part of the application’s data access layer, which you write.
However, nothing prevents you from adopting a kind of declarative approach for it using the code In this case, Get Data is a public method of the page’s code-behind class.
Note that when Data Source ID is bound to a data source control, you don’t need to call Data Bind.
Every data bound control implements two properties: Data Source and Data Source ID.
Each control also has an additional set of data binding properties.
NET control markup and require a call to the Data Bind method.
Data source controls are designed to interact with data bound controls and hide the complexity of the manual data binding process.
The data source can be virtually any software component that exposes data, including in-memory elements (e.g., arrays, collections), properties of live objects, and stream-based data flows (e.g., result sets from database queries). This association is established at compile time and buried in the folds of the code that ASP. Web Figure 1: Data binding in action If you don’t want to call Data Bind on each page in which you intend to use data binding, you can craft a new page class that overrides the On Load method. This code creates the Data Binding Page class, which loads the Data Bind method instead of the On Load method when the Load event is triggered.