DataSourceControl Class
Assembly: System.Web (in system.web.dll)
[BindableAttribute(false)] public ref class DataSourceControl abstract : public Control, IDataSource, IListSource
/** @attribute BindableAttribute(false) */ public abstract class DataSourceControl extends Control implements IDataSource, IListSource
BindableAttribute(false) public abstract class DataSourceControl extends Control implements IDataSource, IListSource
Not applicable.
ASP.NET supports a control data-binding architecture that enables Web server controls to bind to data in a consistent fashion. Web server controls that bind to data are referred to as data-bound controls, and the classes that facilitate that binding are called data source controls. Data source controls can represent any data source: a relational database, a file, a stream, a business object, and so on. Data source controls present data in a consistent way to data-bound controls, regardless of the source or format of the underlying data.
You use the data source controls that are provided with ASP.NET, including SqlDataSource, AccessDataSource, and XmlDataSource, to perform most Web development tasks. You use the base DataSourceControl class when you want to implement your own custom data source control.
While any class that implements the IDataSource interface is a data source control, most ASP.NET data source controls extend the abstract DataSourceControl class, which provides a base implementation of the IDataSource interface. The DataSourceControl class also provides an implementation of the IListSource interface, which enables you to programmatically assign the data source control to the DataSource property of a data-bound control and return data to the control as a basic list.
Any ASP.NET control that derives from the DataBoundControl class can bind to a data source control. When a DataBoundControl is bound to a data source control, data binding is performed automatically at run time. You can also use data source controls with ASP.NET controls that expose a DataSource or DataSourceID property and support basic data binding, but are not derived from DataBoundControl. When using these data-bound controls, you must explicitly call the DataBind method. For more information on data binding, see Accessing Data with ASP.NET.
You can think of a data source control as the combination of the DataSourceControl object and its associated lists of data, called data source views. Each list of data is represented by a DataSourceView object. Because the underlying data storage contains one or more lists of data, a DataSourceControl is always associated with one or more named DataSourceView objects. The IDataSource interface defines the methods that all data source controls use to interact with data source views: the GetViewNames method is used to enumerate the data source views currently associated with the data source control, and the GetView method is used to retrieve a specific data source view instance by name.
You can also think of the data source control as two distinct interfaces that callers use to access data. The DataSourceControl class is the interface that page developers interact with directly when developing a Web Forms page, and the DataSourceView class is the interface that data-bound controls and data-bound control authors interact with. Because the DataSourceView object is available only at run time, any state persisted for the data source control or data source view must be exposed directly by the data source control.
There is no visual rendering of ASP.NET data source controls; they are implemented as controls so you can create them declaratively, and to optionally allow them to participate in state management. As a result, data source controls do not support visual features such as EnableTheming or SkinID.
The following code example demonstrates how a class can extend the DataSourceControl class. The CsvDataSource control represents comma-separated file data stored in a .csv file. The CsvDataSource class provides its own implementations of the GetView, GetViewNames, and other methods, because the base class implementations are not functional.
The following code example demonstrates how to use the CsvDataSource control in a Web form.
- AspNetHostingPermission for operating in a hosted environment. Demand value: LinkDemand; Permission value: Minimal.
- AspNetHostingPermission for operating in a hosted environment. Demand value: InheritanceDemand; Permission value: Minimal.
System.Web.UI.Control
System.Web.UI.DataSourceControl
System.Web.UI.WebControls.ObjectDataSource
System.Web.UI.WebControls.SqlDataSource