HtmlSelect.DataTextField Property

 
System_CAPS_noteNote

The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

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)

abstract DataTextField : string with get, set
override DataTextField : string with get, set

Property Value

Type: System.String

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 collection that implements the System.Collections.IEnumerable or System.ComponentModel.IListSource interfaces (such as System.Data.DataView, System.Collections.ArrayList, or System.Collections.Generic.List<'T>). 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.

.NET Framework
Available since 1.1
Return to top
Show: