Alternating background colors for data repeater items

0
0

I’ve bound a datatable of items to a datarepeater using a binding source. What I want to do now is change the background color for every other row by checking if the row index is odd or even. That part is easy enough, but once I know that, how do I loop through and change the rows I want to change.

I have an item template setup for each row, but there is no DataRepeater.Items property to loop through. DataRepeater.Controls has a count of 0 after binding so that doesn’t work either. The ItemsAdded event doesn’t seem to fire after binding either, so I don’t know how I can loop through each row and access each item?

 

 

  • You must to post comments
0
0

You can’t loop through the items, they don’t exist. The datarepeater clones and reuses only the necessary items for the view + PrefetchItems. You can have 1M rows and the data repeater will only create 5 items if that’s what fits in the panel and when you scroll it reuses the existing controls.

Use the ItemUpdate event to manipulate the item panel after it’s updated. Or bind the color to the data source. The DisplayedItems property gives you access to the items currently created and displayed but as they get reused there is no guarantee on the position.

 

  • You must to post comments
Showing 1 result
Your Answer

Please first to submit.