How to prevent duplicate data in the grid view?

2.7k views Asked by At

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

3

There are 3 answers

0
Uriil On BEST ANSWER

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

0
Clarice Bouwer On

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.

0
Ivan Spahiyski On

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() .