System.Web.UI.WebControls.DataKeyCollection Class

Represents a collection that contains the key field of each record in a data source. This class cannot be inherited.

See Also: DataKeyCollection Members


public sealed class DataKeyCollection : ICollection


The System.Web.UI.WebControls.DataKeyCollection class represents a collection of the key fields in the data source. The key field of each record in the data source is stored in this collection. This allows you to store the key field with a data listing control without displaying it in the control. This collection is automatically filled with the values from the field specified by the BaseDataList.DataKeyField property. This collection does not allow you to manually add or remove items from the collection.

The key field is commonly used in a handler for an event, such as ItemCommand or DeleteCommand, as part of an update query string to revise a specific record in the data source. The key field helps the update query string identify the appropriate record to modify.

Use the DataKeyCollection.Count property to determine the number of items in the collection. To programmatically retrieve a key field from a System.Web.UI.WebControls.DataKeyCollection, use one of following methods:


Namespace: System.Web.UI.WebControls
Assembly: System.Web (in System.Web.dll)
Assembly Versions: 1.0.5000.0,