Click here to Skip to main content
14,876,191 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all. I have a GridView that has over 200 rows. I want to change the background color where my Reference number is duplicates. I bind the data to my GridView in my code behind.
How do you do it?

Your help would be appreciated :-)
Posted

1 solution

Change your query to include count of occurrence using group by, if possible.
Then you can directly use RowDataBound event
If (e.Row.DataItem("occurrence") > 1) Then
 e.Row.BackColor = Drawing.Color.Red
End If  


Otherwise, you need to loop through rows, and check whether it is duplicate or not and set the BackColor accordingly.
   
Comments
Gericke Hoeksema 27-Jun-11 7:51am
   
Thanks I have improved my query with the group by clause aslo by adding count to see all the duplicates, now I have another question.
Is it possible to set for every second duplicate a colour so that I only have 2 different colours seperating them that will still be readable for the user?
Prerak Patel 27-Jun-11 8:05am
   
For your case, I think second option would have been better, as you don't want to highlight both the rows.
Gericke Hoeksema 27-Jun-11 8:31am
   
Thats the thing I want to highlight all the rows.
for example some ref. numbers has between 2 and 7 duplicates. I want a chest board effect in my GridView. For the first Ref. number that has for example 2 duplicates must be red, the second Ref. number must with the duplicates must be blue. I hope my explanation is clearly now?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900