GridSettingsBase.KeyFieldName Property
Gets or sets the name of the data source key field.
Namespace: DevExpress.Web.Mvc
Assembly: DevExpress.Web.Mvc5.v24.1.dll
NuGet Package: DevExpress.Web.Mvc5
Declaration
Property Value
Type | Description |
---|---|
String | A String value that specifies the name of the data source key field. |
Remarks
The KeyFieldName property should be specified when using the following GridView extension features:
- data editing;
- adding new and deleting existing rows;
- selecting rows;
- master-detail view;
- endless paging.
Limitations
- Key field values must be unique.
- Complex type key values are not allowed. Refer to the following topic for more information: The control cannot serialize complex primary key field values.
- It is not possible to use the edit form to update a key field value.
The GridSettingsBase property supports a composite KeyFieldName property value. You can use semicolon-separated values to specify multi-field keys, for example:
Example
@Html.DevExpress().GridView(settings => {
settings.Name = "gvDataBindingToLinq";
settings.CallbackRouteValues = new { Controller = "DataBinding", Action = "DataBindingToLargeDatabasePartial" };
settings.KeyFieldName = "ID";
...
}).BindToEF(string.Empty, string.Empty, (s, e) => {
e.QueryableSource = LargeDatabaseDataProvider.DB.Emails;
}).GetHtml()
Online Demo
Related GitHub Examples
The following code snippets (auto-collected from DevExpress Examples) contain references to the KeyFieldName property.
Note
The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.