Change the color of a td tag of a WebGrid mvc

1

This is WebGrid and you need to change the background color of Celula filled "IN PROCESSING": to Red :

CSS

<styletype="text/css">
    .grid {
        margin: 4px;
        border-collapse: collapse;
        width: 100%;
    }

    .head {
        background-color: #E8E8E8;
        font-weight: bold;
        color: #FFF;
    }

    .grid th, .grid td {
        border: 1px solid #C0C0C0;
        padding: 5px;
    }

    .alt {
        background-color: #E8E8E8;
        color: #000;
    }
</style>

I mount the WebGrid columns this way in code behid:

List<WebGridColumn> columns = new List<WebGridColumn>();
foreach (DataColumn col in dt.Columns)
{
    columns.Add(new WebGridColumn()
    {
        ColumnName = col.ColumnName,
        Header = col.ColumnName,
        Format = (item) =>
        {
            if (valor == "EM PROCESSAMENTO")                                        
            {
                return new HtmlString("<font color='blue'><b>EM PROCESSAMENTO</b></font>"); //Pintar o fundo da Celula em vermelho.
            }                                
        }
    });
});
    
asked by anonymous 24.05.2017 / 14:59

1 answer

1

I think you just need to define a CSS rule:

.grid td.em-processamento {
    background-color: red;
}

And use this class in the DataColumn's Style property:

List<WebGridColumn> columns = new List<WebGridColumn>();
foreach (DataColumn col in dt.Columns)
{
    columns.Add(new WebGridColumn()
    {
        ColumnName = col.ColumnName,
        Header = col.ColumnName,
        Format = (item) =>
        {
            if (valor == "EM PROCESSAMENTO")                                        
            {
                return new HtmlString("<font color='blue'><b>EM PROCESSAMENTO</b></font>"); //Pintar o fundo da Celula em vermelho.
            }                                
        },
        Style = (valor == "EM PROCESSAMENTO") ? "em-processamento" : "";
    });
});
    
26.05.2017 / 17:42