When we represent some data in a grid view we usually prefer to set alternative row color. For this we can use two css classes with different background colors or inline styles. What we need to do is that while constructing the grid by looping through data set, we can check the loop count is odd or even and then attach an alternative class or inline CSS accordingly.

Suppose we need two alternative colors ‘#ffffff’ and ‘#dedede’ .

Using jQuery we can do this very easily.

jQuery provides :even and :odd selectors through which we can select odd and even element and set background color.