HtmlSelect.DataSource Property

Gets or sets the source of information to bind to the HtmlSelect control.

Namespace: System.Web.UI.HtmlControls
Assembly: System.Web (in system.web.dll)

public:
virtual property Object^ DataSource {
	Object^ get ();
	void set (Object^ value);
}
/** @property */
public Object get_DataSource ()

/** @property */
public void set_DataSource (Object value)

public function get DataSource () : Object

public function set DataSource (value : Object)

Not applicable.

Property Value

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).

Exception typeCondition

ArgumentException

The specified data source is not compatible with either System.Collections.IEnumerable or System.ComponentModel.IListSource, and it is not a null reference (Nothing in Visual Basic).

HttpException

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

Use the DataSource property to specify the data source to bind to the HtmlSelect control. A data source must be an object that implements either the System.Collections.IEnumerable interface (such as System.Data.DataView, System.Collections.ArrayList, or System.Collections.Hashtable) or the IListSource interface. When you set the DataSource property, you must manually write the code to perform data binding.

If the data source contains multiple sets of data, such as a System.Data.DataSet object with multiple tables, use the DataMember property to specify which data set to bind to the control.

You can specify which fields from the data source to bind to the ListItem.Text and ListItem.Value properties of each item in the control by setting the DataTextField and DataValueField properties, respectively.

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 a System.Web.HttpException exception is thrown.

The following code example demonstrates how to use the DataSource property to specify the source of information to bind to the HtmlSelect control.

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

Windows 98, Windows Server 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

Community Additions

ADD
Show: