asp.net.ph

Skip Navigation LinksHome > Data Access / ADO.NET > Data Source Controls Overview > Introduction to Data Source Controls

Introduction to Data Source Controls

Binding to Data Using a Data Source Control


ASP.NET includes a set of data source controls that simplify working with various types of data sources on a Web Forms page.

Data source controls can connect to and retrieve data from a database, an XML file, or a middle-tier business object, and make these data readily available for other controls to bind to, without requiring complex coding. Moreover, data source controls have made it appreciably simpler to modify the underlying data source.

This topic provides information about the different types of data source controls in ASP.NET. The data source control model is extensible, offering authors the ability to develop custom-defined data source controls to interact with other types of data sources, or to provide additional functionality for an existing data source.

Data Source Control Comparison

The following table lists the built-in data source controls available in the .NET Framework, and briefly describes what they are used for.

Data source control Description
AccessDataSource Facilitates working with a Microsoft Access database. Supports sorting, filtering, and paging when data is returned as a DataSet object.
ObjectDataSource Facilitates working with business classes or objects to create Web applications that rely on middle-tier objects to manage data. Supports advanced sorting and paging scenarios unavailable with the other data source controls.
SiteMapDataSource Facilitates working with ASP.NET site navigation controls.
SqlDataSource Facilitates working with Microsoft SQL Server, OLE DB, ODBC, or Oracle databases. When used with SQL Server, supports advanced caching capabilities. The control also supports sorting, filtering, and paging when data is returned as a DataSet object.
XmlDataSource Facilitates working with an XML file, especially for hierarchical ASP.NET server controls such as the TreeView or Menu control. Supports filtering capabilities using XPath expressions and supports XSLT transformation to the data. The XmlDataSource enables updating data by saving the entire XML document with changes.

AccessDataSource Control

The AccessDataSource control is a specialized version of the SqlDataSource control, designed to work specifically with Microsoft Access .mdb files. As with the SqlDataSource control, SQL statements are used to define how the control fetches and retrieves data.

For more information, see AccessDataSource Web Server Control.

ObjectDataSource Control

The ObjectDataSource control works with a business object or other class in Web applications that rely on middle-tier business objects to manage data. The control is designed to interact with an object that implements one or more methods to retrieve or modify data. Data-bound controls interact with the ObjectDataSource control by passing values as parameters in method calls to the source object.

The source object’s data-retrieval methods must return a DataSet, DataTable, or DataView object, or an object that implements the IEnumerable interface. If the data is returned as a DataSet, DataTable, or DataView object, the ObjectDataSource control can cache and filter the data. The control can implement advanced paging scenarios if the source object accepts page size and record index information from the ObjectDataSource control.

For more information, see ObjectDataSource Web Server Control.

SiteMapDataSource Control

The SiteMapDataSource control works with ASP.NET site maps and provides site navigation data. It is most commonly used with the Menu control. The SiteMapDataSource control is also useful for customizing site navigation, using site map data with Web server controls that are not specifically designed for navigation, such as the TreeView or DropDownList controls.

For more information, see SiteMapDataSource Web Server Control.

SqlDataSource Control

The SqlDataSource control retrieves and modifies data using SQL commands. The SqlDataSource control works with Microsoft SQL Server, OLE DB, ODBC, and Oracle databases.

The SqlDataSource control can return results as a DataReader or a DataSet object. The control supports sorting, filtering, and caching data when the results are returned as a DataSet. When working with Microsoft SQL Server, the control has the added benefit of using the SqlCacheDependency object, to validaie cache results when the database changes.

For more information, see SqlDataSource Web Server Control.

XmlDataSource Control

The XmlDataSource control reads and writes XML data that can work with heirarchichal data controls such as the TreeView and Menu controls. The XmlDataSource control can read either an XML file or an XML stream. When working with an XML file, the control can write modified XML back to the source file. If a schema that describes the data is available, the XmlDataSource control can use the schema to expose data using typed members.

The control supports applying an XSLT transformation to the XML data, which allows restructuring the raw data from the XML file into a format better suited to the control bound to the XML data.

The control also supports applying XPath expressions to the XML data, which allows filtering the XML data to return only certain nodes in the XML tree, to look for nodes with specific values, and so on. Using XPath expressions, though, disables the insertion of new data.

For more information, see XmlDataSource Web Server Control.

See Also

Binding to Data Using a Data Source Control



© 2025 Reynald Nuñez and asp.net.ph. All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note