Code
ASP.NET datagrid conditional formatting
The idea to conditionally formatting cells in an ASP.NET data grid lies simply with the ItemDataBound Event of the datagrid.
Example:
protected void gridData_ItemDataBound(object sender, DataGridItemEventArgs e) { if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) { Customer cust = (Customer)e.Item.DataItem;
Int32 daysRemaining =cust.SubscriptionDaysRemaining; if (daysRemaining <= 0) { e.Item.Cells[12].ForeColor = Color.Red; e.Item.Cells[12].Font.Bold = true; e.Item.Cells[12].Font.Italic = true; e.Item.Cells[12].Font.Size = new FontUnit(16); }
}