Dailycode.info

Short solution for short problems

Devexpress aspxgrid: Change row color at runtime

 

I needed to change the background color of a grid at runtime.

Found a good and easy solution on how to do this. You will need to override the HTMLRowPrepared event.

protected void grdOrderLocations_HtmlRowPrepared(object sender, DevExpress.Web.ASPxGridView.ASPxGridViewTableRowEventArgs e)

{

CheckBlocked(e);

}

 

private void CheckBlocked(ASPxGridViewTableRowEventArgs e)

{

    if (e.RowType != GridViewRowType.Data) return;

    object blocked = e.GetValue("BlockCodeIC");

    if (blocked != null)

        e.Row.BackColor = System.Drawing.Color.Red;

}

 

This is how it looks: