ListView::DataKeyNames Property

 

Gets or sets an array that contains the names of the primary key fields for the items displayed in a ListView control.

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

public:
[TypeConverterAttribute((StringArrayConverter^::typeid))]
property array<String^>^ DataKeyNames {
	virtual array<String^>^ get();
	virtual void set(array<String^>^ value);
}

Property Value

Type: array<System::String^>^

An array that contains the names of the primary key fields for the items displayed in a ListView control.

Use the DataKeyNames property to specify the field or fields that represent the primary key of the data source. To set this property declaratively, use a comma-separated list of field names.

When the DataKeyNames property is set, the ListView control automatically populates its DataKeys collection with the values from the specified field or fields. This provides a convenient way to access the primary keys of each item.

System_CAPS_security Security Note

The ListView control stores key field values in the control-state field. If these values contain sensitive information, we recommend that you enable view-state encryption by setting the ViewStateEncryptionMode property to ViewStateEncryptionMode.Always.

You must set the DataKeyNames property for the automatic updating and deleting features of the ListView control to work. The values of these key fields are passed to the data source control in order to match the item to update or delete.

Fields that are specified as data keys by using the DataKeyNames property are passed to the data source control during update and delete operations by using the Keys collection. Data key fields are passed to the data source control even if they are not bound to controls in a template.

The following example shows how to use the DataKeyNames property to specify the key field of the data source.

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

.NET Framework
Available since 3.5
Return to top
Show: