Export (0) Print
Expand All

BaseDataList.DataSource Property

Gets or sets the source containing a list of values used to populate the items within the control.

Namespace:  System.Web.UI.WebControls
Assembly:  System.Web (in System.Web.dll)

[<BindableAttribute(true)>]
[<ThemeableAttribute(false)>]
abstract DataSource : Object with get, set
[<BindableAttribute(true)>]
[<ThemeableAttribute(false)>]
override DataSource : Object with get, set
<asp:BaseDataList DataSource="Object" />

Property Value

Type: System.Object
An IEnumerable or IListSource that contains a collection of values used to supply data to this control. The default value is a null reference (Nothing in Visual Basic).

ExceptionCondition
HttpException

The data source cannot be resolved because a value is specified for both the DataSource property and the DataSourceID property.

ArgumentException

The data source is of an invalid type. The data source must be a null reference (Nothing in Visual Basic) or implement either the IEnumerable or the IListSource interface.

Use the DataSource property to specify the source of values to bind to a data listing control. A data source must be a collection that implements either the System.Collections.IEnumerable interface (such as System.Data.DataView, System.Collections.ArrayList, or System.Collections.Generic.List(T)) or the IListSource interface to bind to a control derived from the BaseDataList class. When you set the DataSource property, you must manually write the code to perform data binding.

If the data source specified by the DataSource property contains multiple sources of data, use the DataMember property to specify the specific source to bind to the control. For example, if you have a System.Data.DataSet object with multiple tables, you must specify which table to bind to the control. After you have specified the data source, use the DataBind method to bind the data source to the control.

Alternately, you can use the DataSourceID property to automatically bind to a data source represented by a data source control. When you set the DataSourceID property, the data listing control automatically binds to the specified data source control. You do not need to write code that explicitly calls the DataBind method.

If values are specified for both the DataSource property and the DataSourceID property, ASP.NET is not able to resolve the data source and an System.Web.HttpException exception is thrown.

This property cannot be set by themes or style sheet themes. For more information, see ThemeableAttribute and ASP.NET Themes and Skins.

The following code example demonstrates how to use the DataSource property to specify the data source to bind to a DataGrid control.

No code example is currently available or this language may not be supported.

.NET Framework

Supported in: 4.5.3, 4, 3.5, 3.0, 2.0, 1.1, 1.0

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft