Поделиться через


Data Source Web Server Controls

Data source controls are ASP.NET controls that manage the tasks of connecting to a data source and reading and writing data. Data source controls do not render any user interface, but instead act as an intermediary between a particular data store (such as a database, business object, or XML file) and other controls on the ASP.NET web page. Data source controls enable rich capabilities for retrieving and modifying data, including querying, sorting, paging, filtering, updating, deleting, and inserting. Data source controls derive from ContextDataSource, which is the base class that provides the context type that data source controls use. This base class enables you to create custom data source controls.

Warning

If you are just getting started with ASP.NET Web Forms, you might want to consider using Web Forms Model Binders instead of data source controls. For more information, see ASP.NET Data Access Options.

Overview of Data Source Controls

ASP.NET includes the following data source controls:

Data source control

Description

EntityDataSource control

Enables you to bind to data that is based on an Entity Data Model (EDM), using the Entity Framework. Supports automatic generation of update, insert, delete, and select commands. The control also supports sorting, filtering and paging and can be used with the QueryExtender control..

For more information, see EntityDataSource Web Server Control Overview and QueryExtender Web Server Control Overview.

SqlDataSource control

Enables you to work with ADO.NET managed data providers, which provide access to Microsoft SQL Server, OLE DB, ODBC, or Oracle databases. The control can return results as a DataReader or a DataSet object. It supports sorting, filtering, and caching when the results are returned as a DataSet object. When you are working with Microsoft SQL Server, the control has the added benefit that cache results can be invalidated when the database changes, using a SqlCacheDependency object.

For more information, see SqlDataSource Web Server Control Overview.

ObjectDataSource control

Enables you to work with a business object or other class and create web applications that rely on middle-tier objects to manage data. The control is designed to interact with an object that implements one or more methods to retrieve or modify data. When data-bound controls interact with the ObjectDataSource control to retrieve or modify data, the ObjectDataSource control passes values from the bound control to the source object as parameters in method calls.

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. You can also 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 Overview. (If you are considering using the ObjectDataSource control, see ASP.NET Data Access Options to determine if Web Forms Model Binders might be a better choice.)

LinqDataSource control

Enables you to bind to data that is based on LINQ to SQL classes. Supports automatic generation of select, update, insert, and delete commands. The control also supports sorting, filtering, and paging.

For more information, see LINQ Data Source Control Overview.

XmlDataSource control

Enables you to work with an XML file, which is especially useful for hierarchical ASP.NET server controls such as the TreeView or Menu control. The XmlDataSource control can read either an XML file or string of XML. If the control is working with an XML file, it can write modified XML back to the source file. If a schema is available that describes the data, the XmlDataSource control can use the schema to expose data using typed members.

You can apply an XSLT transformation to the XML data, which allows you to restructure the raw data from the XML file into a format better suited to the control you want to bind to the XML data.

You can also apply XPath expressions to the XML data, which allows you to filter the XML data to return only certain nodes in the XML tree, to look for nodes that have specific values in them, and so on. Using an XPath expression disables the ability to insert new data.

For more information, see XmlDataSource Web Server Control Overview.

SiteMapDataSource control

Used most commonly with the Menu control. The SiteMapDataSource control is also useful when you want to customize 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 ASP.NET Site Navigation.

See Also

Concepts

Using Parameters with Data Source Controls for Filtering

Using Parameters with Data Source Controls for Inserting and Updating

Other Resources

ASP.NET Data Access Content Map