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

Change Row Background After Sort

2 Answers 46 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Steven
Top achievements
Rank 1
Steven asked on 02 May 2013, 04:13 PM
Hi there,

I would like to change the row background of the first 5 rows after the data on the grid has been sorted but I am having a couple of issues.

I hook into the Sorted event and get the rows from the grid and I loop through the first five and set the background. This almost works but it only changes the backgrounds of every second row. I think that the AlternateRowBackground set on the grid is overwriting the value I set.

Another issue I am facing is that there are two ways in which I sort the grid. The above approach only works when the user sorts by clicking on a column. However the Sorted event doesn't seem to fire when I add a SortDescriptor in the code-behind and I'm not sure why.

Is there something obvious that I am missing? Or is there a better approach to achieve what I am looking for?

Thanks,

Steven

2 Answers, 1 is accepted

Sort by
0
Accepted
Dimitrina
Telerik team
answered on 03 May 2013, 06:17 AM
Hello Steven,

Actually the Sorting event is an UI event and it will be invoked only when the Sorting is done by the user clicking on the column's header.

To achieve your goal I would suggest you to apply a RowStyleSelector and return a "colored" RowStyle for the first 5 items in the GridView's Items collection. You can check this help article for a reference on how to define a RowStyleSelector.

Kind regards,
Didie
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Steven
Top achievements
Rank 1
answered on 03 May 2013, 07:50 AM
The style selector works perfectly.

Thanks,

Steven
Tags
GridView
Asked by
Steven
Top achievements
Rank 1
Answers by
Dimitrina
Telerik team
Steven
Top achievements
Rank 1
Share this question
or