Styling Rows

Before reading this topic, you might find it useful to get familiar with the Template Structure of the GridViewRow.

In this article we will discuss the following topics:

Figure 1: GridViewRow template structure

Telerik Silverlight DataGrid-row-template

Targeting the GridViewRow Element

In order to style all RadGridView rows of an application, you should create an appropriate style targeting the GridViewRow element.

You have two options:

  • To create an empty style and set it up on your own.

  • To copy the default style of the control and modify it.

To learn how to modify the default GridViewCell style, please refer to the Modifying Default Styles article.

Example 1: Styling all rows of an application

<Style TargetType="telerik:GridViewRow"> 
    <Setter Property="Background" Value="Red"/> 
    <Setter Property="Foreground" Value="White"/> 

If you're using Implicit Styles, you should base your style on the GridViewRowStyle.

Setting RadGridView's RowStyle and AlternateRowStyle

RadGridView exposes the RowStyle and AlternateRowStyle properties of type Style. GridViewRow elements can be styled by providing an appropriate style for each of these properties.

In order to use the AlternateRowStyle, you should first set the AlternationCount property of your RadGridView. For example, if you want to alternate each second row, you have to set its value to 2.

Example 2: Setting a column's CellStyle

<telerik:RadGridView RowStyle="{StaticResource GridViewRowStyle}" 
AlternateRowStyle="{StaticResource GridViewAlternateRowStyle}" /> 

Figure 2: RadGridView with styled rows

Telerik Silverlight DataGrid-styled-row-and-alternate-row

Setting RadGridView's RowStyleSelector and AlternateRowsStyleSelector

You could also use RadGridView's RowStyleSelector and AlternateRowsStyleSelector properties to style rows differently based on a specific condition. More details about how this can be achieved can be found in the RowStyleSelector article.

See Also

In this article