Change Row Background After Sort

3 posts, 1 answers
  1. Steven
    Steven avatar
    39 posts
    Member since:
    Jul 2012

    Posted 02 May 2013 Link to this post

    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. Answer
    Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 03 May 2013 Link to this post

    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.

  3. Steven
    Steven avatar
    39 posts
    Member since:
    Jul 2012

    Posted 03 May 2013 Link to this post

    The style selector works perfectly.

    Thanks,

    Steven
Back to Top