Sponsored Links
ASP.NET 2.0 Tutorials
- Advanced Site Functionality - ASP.NET 2.0
- ASP.NET : Dynamic Image control
- ASP.NET 2.0 Creating Web Wizards
- Displaying Master-Detail Data on Separate Pages in ASP.NET 2.0
- ASP.NET Displaying Master-Detail Data on the Same Page
- ASP.NET DataBound Controls - Details View
- ASP.NET : Using a Grid to Display Detail Information
- ASP.NET 2.0 : Adding Sorting and Paging in GridView
- ASP.NET 2.0 Tutorials : GridView Filtering
- ASP.NET GridView Control
- ASP.NET 2.0 Training : Data Bound Controls
- ASP.NET 2.0 Free Tutorials : SqlDataSource Control
- ASP.NET 2.0 Training : Data Source Object Model
- ASP.NET 2.0 Free Training : Setting Application-Level Caching
- ASP.NET 2.0 Tutorials : Configuring Page-Level Caching
- ASP.NET 2.0 Free Tutorials : Managing Membership and Roles
- ASP.NET 2.0 Free Tutorials : State Management And Caching in ASp.net 2.0
- Forms Authentication in ASP.NET 2.0
- ASP.NET 2.0 Training : ASP.NET Security
- ASP.NET 2.0 Training : Customizing the Session State Mechanism
Tutorials
ASP.NET 2.0ASP.NET 2.0 Training : Data Source Object Model
Table of Contents
ASP.NET 2.0 Training : Data Source Object Model
ASP.NET 2.0 Training : Data Source Object Model - Page 2ASP.NET 2.0 Training : Data Source Object Model
ASP.NET 2.0 Training : Data Source Object Model
In this tutorial you will learn about Data Source Object Model in ASP.NET 2.0, the Rationale of DataSource components, Data Source Control Internals, Tabular DataSource Controls, Hierarchical Data Source Controls, The SqlDataSource Control: Usage and Data Source Parameters.
The Rationale of DataSource components
The ASP.NET 2.0 data source model provides support for a declarative model of data binding. The data source components return and accept data from familiar streams such as SQL, XML, DataSet and from custom formats too. The schema is very approachable, time saving and simplifies the binding mechanism.
The codeless data binding environment of ASP.NET 2.0 does not require the developer to know any SQL or about page life cycles. The glue code is automatically provided by the plumbing of the control and developers can implement data binding scenarios such as display, edit, page and sort functionalities with no code. This model has a lot of similarity with the
The ASP.NET 2.0 code is declarative. It sets up a connection, handles possible parameters, executes the statements and caches the final subset. Everything is tightly integrated with the existing framework of server controls and new properties are added to all the data-bound controls so that every control can be successfully bound to the data source. For instance the DataSourceId is a new property that matches the name of the data source control defined and can list the data from the data source using another control called the Repeater. The code also shows a more compact syntax for binding data.
Data can be bound to a data control using the DataSource Property or the DataSourceId property. Both are mutually exclusive and an exception would be thrown if both are set together. We will be exploring this in greater detail a little later in this lesson and in the next lesson of this series.
As stated earlier, a variety of data sources including custom data sources, are supported using a single model. The component can implement some or all of a standard set of data operations—such as select, insert, Update and Delete. The class determines the operations that will be implemented by the Data control.
The data control fetches and returns the data as an object and the type returned depends on the particular kind of implementation supported and the data can be sorted and filtered if the same is supported. Page developers can use these operations using a number of intuitive method calls on the data source control object. The methods are categorized in the new interface that is peculiar to the control being used.
The data source model is not an alternative to ADO.NET or OLE DB. It forms a layer of code that interfaces between data bound controls and low level API that is used to retrieve data. The low level API can be ADO.NET, System.Xml, or Microsoft Indexing Service or an Excel COM object model. The data, in other words, can be retrieved from any kind of data source irrespective of the kind of data source control used.
At design time the developer has a richer experience in that the simplified set of advanced controls performs I/O operations on generic blocks of data. This speeds up development times and makes page composition easier and simpler. This also ensures that all data access scenarios can be implemented with least amount of code. Additionally designers can work with real time data and consequently give the interface a reasonable schema.
Data Source Control Internals
The purpose of the data source control is that it binds the data control and the data store. A data source control represents one or more named views of data and provides an enumeration of data objects. The data source can be managed using SQL Statements such as SELECT, INSERT, UPDATE and DELETE. The Data source control inherits from the base class Control which can be tabular or hierarchical. The DataSourceControl abstract class serves as the base class for all data source controls and defines the interface between data bound controls and underlying data. This control is not visually rendered but has a declarative persistence as part of the .aspx source code and gives access to the page’s view state.
As repeatedly stated, the data source control exposes the contents of its underlying data source through a set of properties and methods. A number of methods which are common to all the controls are implemented by the IDatasource Interface. This is the base interface for creation of custom controls. It has one event and a few methods only. The DataSourceChanged event requires delegates with the default prototype called EventHandler class. This event is fired whenever there is a change in the data source and it impacts the control that is bound to it. The GetView method collects the name of the data source view to retrieve and return it as a DataSourceView object. The GetViewNames returns a collection of names representing the list of view objects associated with the current instance of the data source control. The DataSourceControl base class does not permit addition of any extra properties or methods.
A data source view architecture looks like a collection of named views. It provides a customized view of data with special settings for viewing, sorting, filtering and other data operations. It is inherited from the DataSourceView class and is associated within the data view control. The CanDelete defines whether deletions are permitted on the underlying data source. CanInsert, defines whether permission to insert into the data source exists. CanPage indicates whether paging can be done on the view. CanSort defines sorting permission for the data view. CanretrieveTotalRowCount indicates whether information about total row count is available. CanUpdate indicates whether update on the data source is allowed. Name returns the name of the current view. The methods in the DataSourceView are Delete, Insert, Select and Update.
Tabular DataSource Controls
The Data source Control can be a tabular control or a hierarchical control. The four data source controls that express data in a tabular form are AccessDataSource, DataSetDataSource, ObjectDataSource and SqlDataSource.
AccessDataSource control represents a connection to an Access Database. It inherits from the SqlDataSource control and does not accept the connectionString and ProviderName properties. The DataFile property will have to be set to point to the actual MDB file. The Jet 4.0 OLE DB provider is used to connect to the database.
Next Page: ASP.NET 2.0 Training : Data Source Object Model - Page 2
Comments
Sponsored Links
