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

Setting backcolor for gridpageritem

5 Answers 51 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Betina
Top achievements
Rank 1
Betina asked on 09 May 2012, 02:06 PM
Hi
I have a grid where I set the backcolor under certain situations, but when sorting one column, that formatting dissapears, I do get a GridPagerItem back in ItemDataBound instead of GridDataItem, so how do I ensure that my backcolor gets set no matter what type of column I have?

This is my code in ItemDAtaBound which works fine except when I click on a c0olumn to sort it, then that column does not have the colors anymore

    If e.Item.OwnerTableView.Name = "AlleTilbud" Then
      If TypeOf (e.Item) Is GridDataItem Then
        Dim item As GridDataItem = e.Item
        Dim farve As System.Drawing.Color = item.BackColor
        If item("tilbudtdato").Text = " " Then
          item.BackColor = System.Drawing.Color.Yellow
          item("statustext").Text = "Ikke i tilbud"
        Else
          item.BackColor = farve
          item("statustext").Text = "Tilbud"
        End If
        If item("svarfristdato").Text <> "&nbsp;" Then
          Dim dt As Date = CDate(item("svarfristdato").Text)
          If dt < Now Then
            item.BackColor = System.Drawing.Color.Red
            item("statustext").Text = "Svarfrist overskredet"
          End If
        End If
        If item("kontraktdato").Text <> "&nbsp;" Then
          item.BackColor = farve
          item("statustext").Text = "Kontrakt udskrevet"
        End If
        If item("status").Text.ToUpper() = "S" Then
          If item("indflyttersaldo").Text <> "&nbsp;" Then
            Dim betalt As Decimal = CDec(item("indflyttersaldo").Text)
            If betalt = 0 Then
              item.BackColor = farve
              item("statustext").Text = "Kontrakt betalt"
            End If
          End If
        End If
      End If
    End If


5 Answers, 1 is accepted

Sort by
0
Tsvetina
Telerik team
answered on 14 May 2012, 10:01 AM
Hi Betina,

When you sort you should also get ItemDataBound to fire for each GridDataItem (see the control event sequence here). If for some reason your code does not execute on sorting, you can try to move it to RadGrid's PreRender event, where you can again loop all items (if you have hierarchy, see this link) and set their colors accordingly.

All the best,
Tsvetina
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Betina
Top achievements
Rank 1
answered on 21 May 2012, 11:33 AM
Hi Tsvetina

I do get the GridDataItem also, bit it seems I get it like this:

ItemDatabound    
   GridDataItem
ItemDataBound
   GridPagerItem

So the GridPagerItem styles seems to overwrite the styling I do.

I'll try to see ig the PreRender works for me
0
Betina
Top achievements
Rank 1
answered on 21 May 2012, 12:47 PM
Hi again

I now put the code in Page.PreRender and it is the last thing called as far as I can see, but my column does not get hte backcolor I set. I am attaching a screenshot of the grid, how it looks when sorted, maybe that can bette explain my problem.
0
Accepted
Princy
Top achievements
Rank 2
answered on 21 May 2012, 02:14 PM
Hello Betina,

Try setting the EnableSkinSortStyles to false in the SortSettings.

ASPX:
<SortingSettings   EnableSkinSortStyles="false"/>

Thanks,
Princy.
0
Betina
Top achievements
Rank 1
answered on 21 May 2012, 02:32 PM
Hi Princy

Thank you, that was just what I needed.
Regards Betina
Tags
Grid
Asked by
Betina
Top achievements
Rank 1
Answers by
Tsvetina
Telerik team
Betina
Top achievements
Rank 1
Princy
Top achievements
Rank 2
Share this question
or