New to Telerik UI for ASP.NET AJAXStart a free 30-day trial

getDataKeyValue

  • Gets a single string parameter representing a DataField bound to the RadGrid and added to the ClientDataKeyNames collection of the MasterTableView/GridTableView.

  • Returns a string of the dataKeyValue, associated with the GridDataItem.

The DataField name passed to the getDataKeyValue method has to be part of the ClientDataKeyNames array of the MasterTableView/GridTableView.

Example:

Call get_dataKeyValue() on row double click:

ASP.NET
<telerik:RadGrid ID="RadGrid1" runat="server" AllowPaging="True" Width="800px" OnNeedDataSource="RadGrid1_NeedDataSource">
    <ClientSettings>
        <ClientEvents OnRowDblClick="onRowDblClick" />
    </ClientSettings>
    <MasterTableView AutoGenerateColumns="False" DataKeyNames="ID" ClientDataKeyNames="ID, LastName">
        <Columns>
            <telerik:GridBoundColumn DataField="ID" DataType="System.Int32"
                FilterControlAltText="Filter ID column" HeaderText="ID"
                ReadOnly="True" SortExpression="ID" UniqueName="ID">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="FirstName"
                FilterControlAltText="Filter FirstName column" HeaderText="First Name"
                SortExpression="FirstName" UniqueName="FirstName">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="LastName"
                FilterControlAltText="Filter LastName column" HeaderText="Last Name"
                SortExpression="LastName" UniqueName="LastName">
            </telerik:GridBoundColumn>
            </Columns>
    </MasterTableView>
</telerik:RadGrid>
JavaScript
function onRowDblClick(sender, args) {
    var dataItem = args.get_item();
    var id = dataItem.getDataKeyValue("ID");
    var lastName = dataItem.getDataKeyValue("LastName");
    alert("Clicked item key values:" + "\n" +
        "ID: " + id + "\n" +
        "Last Name: " + lastName);
}

You can see one more practical example of the method in its dedicated section in the Accessing Grid Cells, Cell Values and Raw DataKey Values Client-Side article.

Not finding the help you need?
Contact Support