Your code shows that it will run only one condition out of two.
If dontRunHandler =false
it will color cells 2 and 3.
else if dontRunHandler =true
it will color cells 0 and 1.
Try to remove if else, and see if it solves a problem.
now this happens because first if statement returns because it thinks that your column is not 0 or 1.
My suggestion to you is to use ColunnCreated event instead. Suppose to be faster and more semantic.
protected void RadGrid1_ColumnCreated(object sender, GridColumnCreatedEventArgs e)
{
if (e.Column.IsBoundToFieldName("ProductID"))
{
e.Column.ItemStyle.CssClass = "MyClass1";
}
else if (e.Column.IsBoundToFieldName("ProductName"))
{
e.Column.ItemStyle.CssClass = "MyClass2";
}
}
...
<style type="text/css">
.MyClass1
{
color: Red;
}
.MyClass2
{
color: Blue;
}
</style>
Do you think this is something that will work for you. Or you are specifically using indexes for some reason?
if you want your example to work, I would do something like this:
e.CellElement.ResetValue(LightVisualElement.DrawFillProperty, ValueResetFlags.Local);
e.CellElement.ResetValue(LightVisualElement.NumberOfColorsProperty, ValueResetFlags.Local);
e.CellElement.ResetValue(LightVisualElement.GradientStyleProperty, ValueResetFlags.Local);
e.CellElement.ResetValue(LightVisualElement.BackColorProperty, ValueResetFlags.Local);
if (e.CellElement.ColumnIndex == 2 || e.CellElement.ColumnIndex == 3)
{
e.CellElement.DrawFill = true;
e.CellElement.NumberOfColors = 1;
e.CellElement.BackColor = Color.LightSlateGray;
e.CellElement.GradientStyle = GradientStyles.Linear;
}
else if (e.CellElement.ColumnIndex == 0 || e.CellElement.ColumnIndex == 1)
{
e.CellElement.DrawFill = true;
e.CellElement.NumberOfColors = 1;
e.CellElement.BackColor = Color.MediumVioletRed;
e.CellElement.GradientStyle = GradientStyles.Linear;
}