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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Color datagrid row in a form

Status
Not open for further replies.

djam

Technical User
Nov 15, 2002
223
CA
Can someone give me a simple example of how I would color a row in a datagrid form. I would like to color the row if a certain condition occurs in a column eg. contains "Order"

thanks

" ahhh computers, how they made our lives much simpler ;) "
 
Something like this should work:
Code:
private void dg1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
	ListItemType itemType = (ListItemType)e.Item.ItemType;
	if(itemType == ListItemType.Header ||
		itemType == ListItemType.Footer ||
		itemType == ListItemType.Separator)
		return;
	object other = DataBinder.Eval(e.Item.DataItem,"yourDataColumn");
	if(other != DBNull.Value)
	{
		if(other.ToString == "Other")
		{	
		e.Item.ForeColor=Color.Red;
		e.Item.BackColor=Color.Yellow;
		}
	}
}
 
I'm working with a Windows form not a web form

thanks

" ahhh computers, how they made our lives much simpler ;) "
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top