“Data keys must be specified on GridView…”: Solution

Symptom:

You run your ASP.NET web application and get the following error:

image

Applies to:

  • ASP.NET WebForms development (any .NET language).

How to reproduce:

  1. Put a GridView on your webform.
  2. Configure its DataSource to be an Object data source.
  3. In the select method options tab, you chose a method that takes a parameter.
  4. Compile and run the page (error above is displayed).

Solution:

  • Let the GridView control know what the key field(s) is/are of your data source.

image

image

image

One Reply to ““Data keys must be specified on GridView…”: Solution”

Leave a Reply