GridView.DataKeyNames Property
Assembly: System.Web (in system.web.dll)
public: virtual property array<String^>^ DataKeyNames { array<String^>^ get (); void set (array<String^>^ value); }
/** @property */ public String[] get_DataKeyNames () /** @property */ public void set_DataKeyNames (String[] value)
public function get DataKeyNames () : String[] public function set DataKeyNames (value : String[])
Property Value
An array that contains the names of the primary key fields for the items displayed in a GridView control.Use the DataKeyNames property to specify the field or fields that represent the primary key of the data source.
Note |
|---|
| To set this property declaratively, use a comma-separated list of field names. |
When the DataKeyNames property is set, the GridView control automatically populates its DataKeys collection with the values from the specified field or fields, which provides a convenient way to access the primary keys of each row.
Note |
|---|
| The GridView control stores these key field values in the control state. If these values contain sensitive information, it is strongly recommended that you enable view-state encryption by setting the ViewStateEncryptionMode property to ViewStateEncryptionMode.Always. |
When using automatically generated field columns (by setting the AutoGenerateColumns property to true), the GridView control automatically ensures that the automatically generated field columns that correspond to the field or fields specified in the DataKeyNames property are read-only.
Note |
|---|
| You must set the DataKeyNames property for the automatic updating and deleting features of the GridView control to work. The values of these key fields are passed to the data source control in order to match the row to update or delete. |
If the Visible property of a column field is set to false, the column is not displayed in the GridView control and the data for the column does not make a round trip to the client. If you want the data for a column that is not visible to make a round trip, add the field name to the DataKeyNames property.
| Topic | Location |
|---|---|
| Walkthrough: Creating a Web Page to Display XML Data | Building ASP .NET Web Applications in Visual Studio |
| Walkthrough: Displaying an XML Document in a Web Forms Page Using Transformations | Building ASP .NET Web Applications in Visual Studio |
Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.
Note