Reputation: 55
My ASPxGridView is loading massive data from the Database. Every time there is a new data load on the grid, I would each Cellstyle color to Display the BackColor according to resource from Database.
I will try to clarify I want to achieve here below:
This is what I tried. It's Working but all the rest of the rows continue to be System.Drawing.Color.Red.That I don't want to see.
protected void ASPxGridViewTicketList_CustomUnboundColumnData(object sender, DevExpress.Web.ASPxGridViewColumnDataEventArgs e)
{
if (e.Column.Caption == "Status")
{
Object is_priority = e.GetListSourceFieldValue("ispriority");
if (is_priority.ToString() == "1")
{
e.Column.CellStyle.BackColor = System.Drawing.Color.Red;
}
else
{
e.Column.CellStyle.BackColor = System.Drawing.Color.AliceBlue;
}
}
}
Do you have a solution for that? Thank you!
Here is an Illustration:
Upvotes: 0
Views: 2971
Reputation: 2173
I think you are trying to change the BackColor in the wrong place. CustomUnboundColumnData is more data related event. When you call
e.Column.CellStyle.BackColor = System.Drawing.Color.Red;
during CustomUnboundColumnData it sets back color for the whole column, i.e. all Status cells.
To set the background color for a specific unbound cell, you need to handle a cell-specific 'paint' event like HtmlDataCellPrepared or row-specific event like HtmlRowCreated.
For HtmlDataCellPrepared example see this post: https://www.devexpress.com/Support/Center/Question/Details/Q308988 . The example should be straightforward. You check the needed column against e.DataColumn.FieldName and the needed column value in e.CellValue, then you can determine if to paint the row red or not.
I trust you'll be able to add handlers to the mentioned events yourself.
HTH
Upvotes: 1