根据具体单元格颜色更改';s数据

本文关键字:数据 单元格 颜色 | 更新日期: 2023-09-27 17:59:15

我有一个连接到访问数据库的datagrid view,其中有一列称为Status。我希望当该列中的任何单元格变为就绪时,该单元格的背景色变为绿色,如果没有就绪,则变为红色。

建议?

根据具体单元格颜色更改';s数据

在网格的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;
    }
}

希望这能对你有所帮助。

您可以在作为的网格视图的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;
            }
        }
    }