System.Web.UI.WebControls.DataKey Class

Represents the primary key field or fields of a record in a data-bound control.

See Also: DataKey Members


public class DataKey : System.Web.UI.IStateManager


The System.Web.UI.WebControls.DataKey class is used to represent the primary key for a record in a data-bound control. The primary key for a record can be composed of one of more fields from the data source. Although the System.Web.UI.WebControls.DataKey class is not a collection, it can store multiple key field values. The key field values are populated when one of the constructors for the System.Web.UI.WebControls.DataKey class is called. You can retrieve a key field value from a System.Web.UI.WebControls.DataKey object in the following ways:

In general, System.Web.UI.WebControls.DataKey objects are automatically generated by data-bound controls when the control's DataKeyNames property is set. The System.Web.UI.WebControls.DataKey objects contain the values of the key field or fields specified in the DataKeyNames property. Data-bound controls that display a single record at a time (such as System.Web.UI.WebControls.DetailsView or System.Web.UI.WebControls.FormView) generally store the System.Web.UI.WebControls.DataKey object for the current record displayed in the DataKey property of the control. Data-bound controls that display multiple records at a time (such as System.Web.UI.WebControls.GridView) generally store the System.Web.UI.WebControls.DataKey objects for each record in the control in a System.Web.UI.WebControls.DataKeyArray collection. The System.Web.UI.WebControls.DataKeyArray collection is then stored in the DataKeys property of the control.


Namespace: System.Web.UI.WebControls
Assembly: System.Web (in System.Web.dll)
Assembly Versions:
Since: .NET 2.0