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