How to apply colors to alternate rows in a ListView?

Tripati_tutu
Posted by Tripati_tutu under ASP.NET category on | Points: 40 | Views : 6679
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;
else
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