How to apply colors to alternate rows in a ListView?

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