How to apply colors to alternate rows in a ListView?

Posted by Tripati_tutu under ASP.NET category on | Points: 40 | Views : 7710
public void SetAlternateColors(ListView lView, Color Red, Color Blue)
//loop through each ListViewItem in the ListView control
foreach (ListViewItem item in lView.Items)
if ((item.Index % 2) == 0)
item.BackColor = Red;
item.BackColor = Blue;

To work with this color class, you have to include the "using System.Drawing;" namespace.

Comments or Responses

Login to post response