Click here to Skip to main content
15,885,875 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hello,
i want to set a back color to a special row in my Gridview using c#
i tried the exemple below but it doesn't seems to work

exemple 1
GridView1.Rows[3].BackColor = System.Drawing.Color.Red;
exemple 2
this.dataGridView1.Rows[3].DefaultCellStyle.BackColor = Color.Yellow;

do i need other includs to use "DefaultCellStyle" ?
thanks
Posted
Comments
Peter Leow 23-Mar-14 10:17am    
Your first line of code should work. Is GridView1 the correct id?
Member 10656162 23-Mar-14 15:35pm    
yes GridView1 is the correct id but it's not working
Richard.Berry100 23-Mar-14 13:03pm    
This works for me for single cell:

DataGridViewCellStyle CellStyle = new DataGridViewCellStyle();
CellStyle.BackColor = Color.Yellow;
this.dataGridView1.Rows[r].Cells[c].Style = CellStyle;
Member 10656162 23-Mar-14 15:38pm    
sorry it was my mistake in exemple 2
we only have gridview in ASP.net , not DataGridView
Maciej Los 23-Mar-14 16:41pm    
Which gridview: WPF, WebControl, WinForm?

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