Gets the data-key value of the selected item in a ListView control.
Assembly: System.Web.Extensions (in System.Web.Extensions.dll)
The DataKeyNames property can be set to a comma-separated list of field names that represent the primary key of the data source. If it is set, the ListView control automatically creates a DataKey object for each item in the control by using the value or values of the specified field or fields. The DataKey objects are then added to the control's DataKeys collection.
Normally, the DataKeys property is used to get the DataKey object for a specific data item in the ListView control. However, if you want to get only the DataKey object of the currently selected item, you can use the SelectedDataKey property as a shortcut. You can also directly determine the data-key value of the first key field of the selected item by using the property.
The following example shows how to use the first key field as a parameter in a master/detail scenario. When an item is selected in the ListView control, the property is used as the PropertyName for the ControlParameter object. This parameter object is in turn used by the SqlDataSource control that the second ListView control is bound to.
The following example shows how to use the property to determine the value of the key field.