HtmlSelect.DataSourceID Property
Assembly: System.Web (in system.web.dll)
/** @property */ public String get_DataSourceID () /** @property */ public void set_DataSourceID (String value)
public function get DataSourceID () : String public function set DataSourceID (value : String)
Not applicable.
Property Value
The programmatic identifier assigned to the data source control. The default value is an empty string (""), which indicates that the property has not been set.| Exception type | Condition |
|---|---|
| The data source cannot be resolved because a value is specified for both the DataSource property and the DataSourceID property. |
Use the DataSourceID property to set or access the ID property of the data source control that the HtmlSelect control should use to retrieve its data source. The data source control referenced by the DataSourceID property can be any control that implements the IDataSource interface. The data source control must exist either in the same naming container as the HtmlSelect control that references it or in a parent control of the HtmlSelect control. When you specify a value for this property, the HtmlSelect control automatically binds to the specified data source control. You do not need to write code that explicitly calls the DataBind method.
Alternately, you can use the DataSource property to specify the source of values to bind to an HtmlSelect control. The data source must be an object that implements 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 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 DataSourceID property to specify the data source for an HtmlSelect control. The DataSourceID property is set to the ID property of the SqlDataSource control used to retrieve the data. When the page is loaded, the HtmlSelect control automatically binds to the data source specified by the SqlDataSource control and the data is displayed to the user.