System.Web.UI.WebControls Namespace FormView Class
.NET Framework version 2.0
Sets or retrieves the names of the primary key fields in the data source bound to the FormView control.
Inline |
<asp:formview datakeynames = strField1, strField2 ... > |
Script |
FormView.DataKeyNames [ = strField1, strField2 ... ] |
strField1, strField2 |
An array specifying the names of the primary key fields in the data source bound to the FormView 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 FormView 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 FormView control's DataKey property.
NOTE: You must set the DataKeyNames property for the built-in updating, deleting, and inserting features of the FormView 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 FormView control.
<asp:formview id = "msgView" runat = "server"
datasourceid = "messages"
datakeynames = "MessageID"
width=80% cellpadding=5
allowpaging
...
>
FormView Members DataKey