1

I have a grid view and this grid view has a DataKeyNames="person_id"

Now I want this key as a primary key for the grid so no allowed duplicates .

How to prevent duplicate data through using DataKeyNames

Anyname Donotcare
  • 11,113
  • 66
  • 219
  • 392

3 Answers3

4

GridView is a presentation layer. It should not do any validation. I suggest you to check for duplicates in Data Access layer.

Uriil
  • 11,948
  • 11
  • 47
  • 68
1

The DataKeyNames can contain duplicate values so you will need to ensure that your data source does not have duplicates for that field. If it does, you can programmatically loop through your grid view after it has bound and manually remove duplicate rows by adding some logic in the code-behind.

Clarice Bouwer
  • 3,631
  • 3
  • 32
  • 55
1

You need to distinct result, from datasource. If you are using SQL query, check it http://www.w3schools.com/sql/sql_distinct.asp . In case you are using LINQ - .Distinct() .