System.Web.UI.WebControls Namespace
Represents a collection of values containing the key field for each record in a data source.
The DataKeyCollection class stores the key field of each record in the data source. 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 is read-only, and does not allow 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 Count property to determine the number of items in the collection. To programmatically retrieve a key field from a DataKeyCollection, use one of following methods:
- Use the indexer to get a single key field from the collection, using array notation.
- Use the CopyTo method to copy the contents of the collection to a System.Array object, which can then be used to get items from the collection.
- Use the GetEnumerator method to create a System.Collections.IEnumerator implemented object, which can then be used to get items from the collection.
BaseDataList