Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Color rows in datagrid based on the cell value

Status
Not open for further replies.

sqlturbo

IS-IT--Management
Mar 11, 2002
67
US
hi,

I am a newbie in C# and I cannot figure this one out.
I want to color the rows in a datagrid based on the value in the first column. How do I do that in C#?

Thanks.
 
You can do it in the ItemDataBound event like so:
Code:
private void YourDataGrid_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
	if(e.Item.Cells[0].Text == "YourValueHere")
	{
		e.Item.BackColor=System.Drawing.Color.Red;
	}
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top