我有一个datagrid view
连接到访问数据库,有一个名为Status
的列。
我希望当该列中的任何单元格更改为准备好时,此单元格的背景颜色变为绿色,如果未准备就变为红色。
建议?
答案 0 :(得分:1)
在网格的DataBound
功能上,您可以检查细胞状况并为细胞着色。
示例:
protected void grd_DataBound(object sender, EventArgs e)
{
foreach (GridViewRow GR in grd.Rows)
{
//Here run loop on your rows and check value of cell of column name Status
GR.Cells[index of cell].BackColor = System.Drawing.Color.Cyan;
}
}
希望这对你有所帮助。
答案 1 :(得分:0)
您可以在网格视图的RowDataBound
事件上执行此操作
protected void gridView_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
//Check the status here
if (status == "ready")
{
e.Row.Cells[0].BackColor = System.Drawing.Color.Green;
}
else
{
e.Row.Cells[0].BackColor = System.Drawing.Color.Red;
}
}
}