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

Alternate Row Color using a style?

7 Answers 700 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Marcus Kellermann
Top achievements
Rank 1
Marcus Kellermann asked on 27 Jun 2007, 07:40 PM
I've seen the knowledge base article on how to change alternating row colors of the details section using a databound event handler.  That article describes setting the processing items background color explicitly.

Could you please provide an example of changing the detail sections style on alternating rows.  I've tried the following but it didn't work.
int counter=0;  
private void detail_ItemDataBound(object sender, EventArgs e)  
    {  
    Telerik.Reporting.Processing.DetailSection section = sender as Telerik.Reporting.Processing.DetailSection;  
    if (section != null)  
        {  
        if (counter % 2 == 0) //even row     
            {  
            section.ItemDefinition.StyleName = "ReportRow";  
            }  
        else //odd row     
            {  
            section.ItemDefinition.StyleName = "ReportRowAlt";  
            }  
        counter++;     
        }   
    }  
 

7 Answers, 1 is accepted

Sort by
0
Svetoslav
Telerik team
answered on 28 Jun 2007, 08:04 AM
Hi Marcus,

In the current implementation changing the StyleName of the definition item will not change anything. This is by design. This property takes effect only if set before a report is being processed.

Nevertheless, your scenario really makes sense. We logged an issue for this thread and will definitely think of a possible resolution. Your points have been updated for giving us a new feature.


Sincerely yours,
Svetoslav
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Nate Pinchot
Top achievements
Rank 1
answered on 09 Jan 2009, 08:32 PM
Has any progress been made on this?
0
Steve
Telerik team
answered on 10 Jan 2009, 03:56 PM
Hi Nate,

You can use the Conditional Formatting item from the context menu of the detail section. More info is available in this help article.

Greetings,
Steve
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
David
Top achievements
Rank 1
answered on 10 May 2011, 05:14 PM
Based on the initial post by Marcus, is there any way of programmatically setting up conditional formatting to provide alternative row styling? (And not by using the Value field in the Conditional Formatting dialog box, I mean in code behind)

I don't really want to create conditional formatting through code, but I can't see and other way to link alternative row colours to the main stylesheet on the report.  The reason I ask is I'm working on a project we're we need to set the alternative row background colour based on a style sheet which we're planning on using across lots and lots of reports. 

Just quickly too, I found the FormattingRule class but failed to find much documentation on it.  I'm thinking that this might be the direction I want to go down.  Any throughts?

Thanks in advance.

David
0
Peter
Telerik team
answered on 13 May 2011, 05:24 PM
Hello Nate Pinchot,

You can achieve your requirement with a user function and a binding expression. Just prepare a user function the returns the required stylesheet color:
public static Color GetColor()
{
    return Color.<from my stylesheet>
}
Build you project and add the following binding:
Property   Expression
Style.BackgroundColor =IIF(RowNumber()%2=1,GetColor(),ReportItem.Style.BackgroundColor) 

Regards,
Peter
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Govind
Top achievements
Rank 1
answered on 17 May 2011, 12:19 PM
Hello Peter,

Thanks for providing a clue for my problem. but i still have one more question on this.
I have an external stylesheet which has stylerule for alternate color like follows..
 
<StyleRule>
<Style BackgroundColor="240, 240, 240">
</Style>
<Selectors>
<StyleSelector>
<Type>TextBox</Type>
<StyleName>AlterNativeRow</StyleName>
</StyleSelector>
</Selectors>
</StyleRule> 

 

I would like to know how can i read this styleName from external style sheet (Alternaterow.xml) and get return the stylename value in the userfunction.
In your sample userfuntion you gave an info like..<from my stylesheet>. but I am unable to complete the part by reading the external style sheet.

Thanks in advance.
Govind

0
Massimiliano Bassili
Top achievements
Rank 1
answered on 20 May 2011, 01:30 PM
Govind, there is plenty of information how to read xml via code in your favorite programming language in articles on the net. You need to include this code in the user function where you would read the xml file and get the style/color you need. The rest is just like Telerik have proposed.

Cheers!
Tags
General Discussions
Asked by
Marcus Kellermann
Top achievements
Rank 1
Answers by
Svetoslav
Telerik team
Nate Pinchot
Top achievements
Rank 1
Steve
Telerik team
David
Top achievements
Rank 1
Peter
Telerik team
Govind
Top achievements
Rank 1
Massimiliano Bassili
Top achievements
Rank 1
Share this question
or