What do you mean with “Dynamically”?
An (out of the box) option would be to have the content multiple times in your grid cell (each with another background color). Based on some rules, you could only make one visible. The one with the color you need.