How to apply alternating row color in a ListBox in listbox alternating row color
ListBox is an web server control. ListBox allow us to select a single or multiple items at a time. By default, ListBox have a property named BackColor which allow us to display a background color for entire ListBox control. But ListBox has no built in property or method to display ListBox items alternating row color. We can apply ListBox alternating row color by applying few techniques.

First we loop through the ListBox items collection by for loop. Next we check the current item's index number is an odd number or even number. If the current item's index number is an odd number then we applied a background color to this item. And if the current item's index number is an even number then we add another background color for the item.

Finally we applied a background color for items whose index number is odd and applied an alternate background color for items whose index number is an even number. As a result ListBox control display alternating row color in its items. We added individual item's background color by adding a css style to its attributes collection. We also applied different color for alternating items text color (forecolor) by following those techniques.

The following c# example code demonstrate us how can apply alternating row text and background color for ListBox items in an application.

<%@ Page Language="C#" AutoEventWireup="true"%>    
<!DOCTYPE html>
<script runat="server">  
    protected void Page_Load(object sender, EventArgs e)  
        if (!Page.IsPostBack)
            string[] birds = { 
                                 "Eurasian Sparrowhawk",
                                 "Yellow-eyed Penguin",
                                 "Fairy Penguin",
                                 "Magellanic Penguin",
                                 "Black Swan",
                                 "Spur-winged Goose"

            ListBox1.DataSource = birds;
        for (int i = 0; i < ListBox1.Items.Count; i++)
            if (i % 2 == 0)
                ListBox1.Items[i].Attributes.Add("style", "color:green;background-color:aliceblue;");
                ListBox1.Items[i].Attributes.Add("style", "color:snow;background-color:seagreen;");
<html xmlns="">        
<head id="Head1" runat="server">        
    <title> listbox alternating row color</title>  
    <form id="form1" runat="server">        
        <h2 style="color:MidnightBlue; font-style:italic;">        
   example - listbox alternating row color
        <hr width="550" align="left" color="Gainsboro" />   
        <br />     
            Font-Names="Comic Sans MS"  
More examples