This is a migrated thread and some comments may be shown as answers.

Set alternating row colour red and blue

2 Answers 125 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Sunil
Top achievements
Rank 1
Sunil asked on 07 Jul 2009, 01:58 PM
Hi,
I am using RadGridview control. I have set EnableAlternatingRowColour =true. It's showing alternate rows in different colour. I want to show my alternate rows in Red and Blue colours. How can I do this. 

2 Answers, 1 is accepted

Sort by
0
Accepted
Jack
Telerik team
answered on 08 Jul 2009, 04:42 PM
Hi Sunil,

You can set the AlternatingRowColor property, If you just want to change the color for the odd rows. Here is a sample:

((GridTableElement)this.radGridView1.GridElement).AlternatingRowColor = Color.Red; 
 

You have two options, if you want to change the both colors:

1. Create or modify an existing theme by using the Visual Style Builder
2. Handle the RowFormatting event and set desired colors. The code snippet below demonstrates how to do this:

void radGridView1_RowFormatting(object sender, RowFormattingEventArgs e) 
    e.RowElement.ResetValue(LightVisualElement.BackColorProperty); 
    e.RowElement.ResetValue(LightVisualElement.GradientStyleProperty); 
    e.RowElement.ResetValue(LightVisualElement.DrawFillProperty); 
 
    if (!e.RowElement.IsCurrent && !e.RowElement.IsSelected) 
    { 
        if (e.RowElement.IsOdd) 
        { 
            e.RowElement.BackColor = Color.Red; 
        } 
        else 
        { 
            e.RowElement.BackColor = Color.Blue; 
        } 
    } 
    else 
    { 
        e.RowElement.BackColor = Color.Yellow; 
    } 
    e.RowElement.DrawFill = true
    e.RowElement.GradientStyle = GradientStyles.Solid; 

If you need further assistance, please don't hesitate to write us.

Best wishes,
Jack
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Sunil
Top achievements
Rank 1
answered on 09 Jul 2009, 04:49 AM
Thanks Jack, it works for me........
Tags
GridView
Asked by
Sunil
Top achievements
Rank 1
Answers by
Jack
Telerik team
Sunil
Top achievements
Rank 1
Share this question
or