System.Web.UI.WebControls Namespace DetailsView Class
.NET Framework version 2.0
Sets or retrieves the names of the primary key fields in the data source bound to the DetailsView control.
Inline |
<asp:detailsview datakeynames = strField1, strField2 ... > |
Script |
DetailsView.DataKeyNames [ = strField1, strField2 ... ] |
strField1, strField2 |
An array specifying the names of the primary key fields in the data source bound to the DetailsView control. |
The property is read/write with no default value.
NOTE: The specified field or fields must contain unique values ( no duplicate entries ).
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 contains the key/value pairs of the field or fields listed in the DataKeyNames property for the current record. This DataKey object is then stored in the DetailsView control's DataKey property.
NOTE: You must set the DataKeyNames property for the built-in updating, deleting, and inserting features of the DetailsView control to work.
The following example demonstrates how to use the DataKeyNames property to specify the key field for the data source bound to the DetailsView control.
<asp:detailsview id = "msgView" runat = "server"
datasourceid = "messages"
datakeynames = "MessageID"
width=80% cellpadding=5
allowpaging
...
>
DetailsView Members DataKey