Click here to Skip to main content
14,735,689 members
Please Sign up or sign in to vote.
3.50/5 (2 votes)
See more:
Hi,
I want to change color of perticular single column of datagrid not all column only one in c# window.How i'll do this.Please give me any codes or any reference or idea.
Thanks in advance
Posted

1 solution

On RowDataBound

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
  e.Row.Cells[2].BackColor = Color.FromName("#c6efce"); 
  // 2: replace with your column index

}


For windows, use CellFormatting
private void DataGridView1_CellFormatting(object sender, System.Windows.Forms.DataGridViewCellFormattingEventArgs e)
{
	if (e.ColumnIndex == 2) {
		e.CellStyle.BackColor = Color.AliceBlue;
	}
}
   
v2
Comments
singh7pankaj 1-Jul-11 6:56am
   
in window not in web
Prerak Patel 1-Jul-11 6:58am
   
Then why you tagged it as ASP.Net?!
singh7pankaj 1-Jul-11 7:36am
   
Ok sorry
Prerak Patel 1-Jul-11 7:37am
   
Anyways, I have updated for forms. Check if it helps.
singh7pankaj 1-Jul-11 7:38am
   
I want that in datagrid because the property which is given by u CellFormatting is not availbale in datagrid.I am using datagrid not datagidview
singh7pankaj 1-Jul-11 8:14am
   
Sir Please give me the answer its very urgent for me

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