Skip to main content
Tab

ASPxGridBase.KeyFieldName Property

Gets or sets the name of the data source key field.

Namespace: DevExpress.Web

Assembly: DevExpress.Web.v24.2.dll

Declaration

[DefaultValue("")]
public string KeyFieldName { get; set; }

Property Value

Type Default Description
String String.Empty

A String value that specifies the name of the data source key field.

Remarks

The KeyFieldName property should be specified when using the following grid features:

  • data editing;
  • adding new and deleting an existing data item (row, card or record);
  • selecting a data item (row, card or record);
  • master-detail view (for ASPxGridView);
  • endless paging.

The KeyFieldName property supports a composite value. You can use semicolon-separated values to specify multi-field keys, for example:

<dx:ASPxGridView ... KeyFieldName="FirstName;LastName;Phone;BirthDate">
     ...
</dx:ASPxGridView>

Limitations

  • The values contained in the key field must be unique.
  • It is not recommended that you use the DateTime column names in the KeyFieldName property value.
  • Negative key values are not supported in Batch Edit Mode. Instead, use a composite value.
  • A key field cannot contain values of a reference type (for instance, arrays).
  • Complex type key values are not allowed. Refer to the following topic for more information: The control cannot serialize complex primary key field values.

The following code snippet illustrates how to select a row when a composite key is used.

ASPxGridView1.Selection.SelectRowByKey("Key1|Key2|...|KeyN");

Example

Note

For a full example, see the ASPxGridView - LargeDatabase (Server Mode) demo.

<dx:ASPxGridView ID="grid" ClientInstanceName="grid" runat="server" KeyFieldName="ID"
    Width="100%" AutoGenerateColumns="False">
    <Columns>
        <dx:GridViewDataTextColumn FieldName="From" Width="200px" />
        <dx:GridViewDataTextColumn FieldName="Subject" />
        <dx:GridViewDataDateColumn FieldName="Sent" Width="100px" />
        <dx:GridViewDataCheckColumn Caption="Attachment?" FieldName="HasAttachment" Width="100px" />
        <dx:GridViewDataTextColumn FieldName="Size" Width="80px">
            <Settings AllowAutoFilter="false" />
        </dx:GridViewDataTextColumn>
    </Columns>
    ...
</dx:ASPxGridView>

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.

See Also