How to change ListBox item background color in listbox item background color
The following c# example code demonstrate us how can we set the ListBox items background color programmatically. This tutorial also applied ListBox alternating items background color.

To do this, we loop through the ListBox items collection. We separated the items based on odd and even number. We set a background color for each odd number list items and another background color for each even number list items. In this example code we uses Beige and PaleGoldenRod color as items background color to easily separate ListBox items.

ListBox ListItem Attribute property have a sub property name CssStyle. We can add CSS style to this CssStyle sub property by using its Add() method. Add() method works as like key value pair. We provided the CSS property name and value to the CssStyle collection. Finally, the ListBox display different background colors for its items.

<%@ Page Language="C#" AutoEventWireup="true"%>    
<!DOCTYPE html>
<script runat="server">  
    protected void Page_Load(object sender, EventArgs e)  
        if (!Page.IsPostBack)
            string[] birds = { 
                                 "Egyptian Goose",
                                 "Blue Duck",
                                 "Orinoco Goose",
                                 "Andean Goose",
                                 "African Pygmy Goose",
                                 "Common Shelduck"

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