在 `RowDataBound` 事件中判斷並設置單元格顏色:
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) {
if (e.Row.RowType == DataControlRowType.DataRow) {
int stock = Convert.ToInt32(DataBinder.Eval(e.Row.DataItem, "StockCount"));
if (stock < 10) {
e.Row.Cells[庫存列索引].ForeColor = System.Drawing.Color.Red;
} else {
e.Row.Cells[庫存列索引].ForeColor = System.Drawing.Color.Green;
}
}
}
或使用模板列 `