Tab

ASPxGridBase.KeyFieldName Property

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

Namespace: DevExpress.Web

Assembly: DevExpress.Web.v21.1.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>
NOTE
  • 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).

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>
See Also