How to count ListBox selected items in listbox selected items count
ListBox is an list web server control. this server control allow us to select a single item or multiple items at a time. listbox has no built in property or method to directly count listbox selected items. to get the listbox selected items number we need to apply few techniques.

first we write an event handler for the listbox SelectedIndexChanged event. when listbox items selection changed we apply a linq query to get its selected items. finally in this linq query we count the selected items collection's objects by using Count() method. the Enumerable.Count() method allow us to get the number of elements in a sequence.

the following c# example code demonstrate us how can we count the listbox selected items programmatically in an application.

<%@ Page Language="C#" AutoEventWireup="true"%>    
<!DOCTYPE html>
<script runat="server">  
    protected void Page_Load(object sender, EventArgs e)  
            //auto height of listbox to remove vertical scrollbar
            ListBox1.Rows = ListBox1.Items.Count;
    protected void ListBox1_SelectedIndexChanged(object sender, EventArgs e)
        //linq query to count all selected items from listbox
        var items = (from ListItem li in ListBox1.Items
                    where li.Selected == true
                    select li).Count();
        Label1.Text = "you selected....<br /><b>";
        Label1.Text += items + "</b> items";
<html xmlns="">        
<head id="Head1" runat="server">        
    <title> listbox selected items count</title>  
    <form id="form1" runat="server">        
        <h2 style="color:MidnightBlue; font-style:italic;">        
   example - listbox selected items count
        <hr width="550" align="left" color="Gainsboro" />        
            Text="select item(s) from listbox."
        <br /><br />  
            Font-Names="Comic Sans MS"
            <asp:ListItem Text="Ochre-breasted Foliage-gleaner" Value="1"></asp:ListItem>
            <asp:ListItem Text="Plain Xenops" Value="2"></asp:ListItem>
            <asp:ListItem Text="White-eyed Foliage-gleaner" Value="3"></asp:ListItem>
            <asp:ListItem Text="Plain-brown Woodcreeper" Value="4"></asp:ListItem>
            <asp:ListItem Text="Scalloped Woodcreeper" Value="5"></asp:ListItem>
More examples