HtmlSelect.DataTextField Property

Gets or sets the field from the data source to bind to the ListItem.Text property of each item in the HtmlSelect control.

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

public:
virtual property String^ DataTextField {
	String^ get ();
	void set (String^ value);
}
/** @property */
public String get_DataTextField ()

/** @property */
public void set_DataTextField (String value)

public function get DataTextField () : String

public function set DataTextField (value : String)

Not applicable.

Property Value

The field from the data source to bind to the ListItem.Text property of each item in the HtmlSelect control. The default value is an empty string (""), which indicates that the property has not been set.

Use the DataTextField property to specify which field from the data source to bind to the ListItem.Text property of each item in the control. This property is commonly used to provide a value for the ListItem.Text property that differs from the value of the ListItem.Value property.

The HtmlSelect class provides two properties for specifying the data source to bind to. The DataSource property allows you to bind an HtmlSelect control to any object that implements the System.Collections.IEnumerable or System.ComponentModel.IListSource interfaces (such as System.Data.DataView, System.Collections.ArrayList, or System.Collections.Hashtable). When you use the DataSource property to specify the data source, you must explicitly call the DataBind method to bind the control and its DataTextField property to the data source.

The DataSourceID property allows you to bind an HtmlSelect control to a data source control that represents a data source. When you use the DataSourceID property to specify the data source, the HtmlSelect control and its DataTextField property automatically bind to the specified data source control. Therefore, you do not need to explicitly call the DataBind method.

The following code example demonstrates how to use the DataSource and DataTextField properties to specify the field from the data source to bind to the ListItem.Text property of each item in the HtmlSelect control.

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

The following code example demonstrates how to use the DataSourceID and DataTextField properties to specify the field from the data source to bind to the ListItem.Value property of each item in 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: