GridView alternative row background color using CSS

By using the option tr:nth-child(even) / tr:nth-child(odd) in CSS we can set the grid / table alter native row background color. below is the sample css for alternative row background color.

CSS Example:

<style type="text/css"> .grid { width:500px; } .grid th { background-color:Green; color:#ffffff; } .grid tr:nth-child(even) { background-color:#ffffff; } .grid tr:nth-child(odd) { background-color:#cccccc; } .grid td { padding-left:10px; } </style>


<asp:GridView ID="gv" runat="server" CssClass="grid"> </asp:GridView>