DetailsView.DataKeyNames Property


Gets or sets an array that contains the names of the key fields for the data source.

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

abstract DataKeyNames : string[] with get, set
override DataKeyNames : string[] with get, set

Property Value

Type: System.String[]

An array that contains the names of the key fields of the data source.

Use the DataKeyNames property to specify a comma-separated list of field names that represent the primary key of the data source. When the DataKeyNames property is set, the DetailsView control automatically creates a DataKey object that represents the key field or fields for the current record and stores it in the DataKey property. When the AutoGenerateColumns property is also set to true, the DetailsView control automatically ensures that the field or fields specified in the DataKeyNames property are read-only.


You must set the DataKeyNames property for the automatic updating, deleting, and inserting features of the DetailsView control to work.

If the Visible property of a row field is set to false, the row is not displayed in the DetailsView control and the data for the row does not make a round trip to the client. If you want the data for a row that is not visible to make a round trip, add the field name to the DataKeyNames property.

The following code example demonstrates how to use the DataKeyNames property to identify the key field for the data source bound to the DetailsView control.

No code example is currently available or this language may not be supported.

.NET Framework
Available since 2.0
Return to top