Gets the data-key value for the selected item in a ListView control.
Assembly: System.Web.Extensions (in System.Web.Extensions.dll)
When the DataKeyNames property is set, the ListView control 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 retrieve the DataKey object for a specific data item in the ListView control. However, if you want to retrieve only the DataKey object of the currently selected item, you can use the property as a shortcut.
Using the DataKey object from the DataKeys collection at the index that is specified by the SelectedIndex property. You can also use the SelectedValue property to retrieve the data-key value for the currently selected item directly.property is the same as retrieving the
The following example shows how to use the second key field as a parameter in a master/detail scenario. A ListView control is used to display records from the Product Inventory table of the AdventureWorks database. When an item is selected in the ListView control, the details of the product are displayed in another ListView control. ProductID is the second key name in the first ListView control. To access the second key, the code uses the value of ProductInventoryListView.SelectedDataKey (ProductInventoryListView.SelectedDataKey(1) in Visual Basic) 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.
Available since 3.5