有条件地格式化DataGrid单元格

 

private void OnDataGridDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
 if (e.Item.ItemType == ListItemType.Item ||
     e.Item.ItemType == ListItemType.AlternatingItem)
 {
  DataRowView rv = (DataRowView)e.Item.DataItem;
  // 获取第四列的值
  Int32 nUnitsInStock = Convert.ToInt32(rv.Row.ItemArray[4]);
  if (nUnitsInStock < 20)
  {
     e.Item.Cells[4].BackColor = Color.Red;
  }
 }
}
posted @ 2004-11-10 02:34  Benny Ng  阅读(394)  评论(0编辑  收藏  举报