HtmlSelect::DataValueField Property

 

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

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

public:
property String^ DataValueField {
	virtual String^ get();
	virtual void set(String^ value);
}

Property Value

Type: System::String^

The field from the data source to bind to the ListItem::Value 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 DataValueField property to specify which field from the data source to bind to the ListItem::Value property of each item in the control. This property is commonly used to provide a value for the ListItem::Value property that differs from the value of the ListItem::Text 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 IEnumerable or 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 DataValueField 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 DataValueField property automatically bind to the 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 DataValueField 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.

The following code example demonstrates how to use the DataSourceID and DataValueField 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: