Refer this
HTML
<div>
<asp:ListBox ID="lbFruits" runat="server" SelectionMode="Multiple" Width="200" Height="150">
<asp:ListItem Text="Mango" Value="Mango" />
<asp:ListItem Text="Banana" Value="Banana" />
<asp:ListItem Text="Apple" Value="Apple" />
<asp:ListItem Text="Orange" Value="Orange" />
<asp:ListItem Text="Guava" Value="Guava" />
<asp:ListItem Text="Strawberry" Value="Strawberry" />
<asp:ListItem Text="Pineapple" Value="Pineapple" />
<asp:ListItem Text="Jackfruit" Value="Jackfruit" />
</asp:ListBox>
<hr />
<asp:Button Text="Count Selected option" OnClick="CountSelectedOption" runat="server" />
</div>
C#
protected void CountSelectedOption(object sender, EventArgs e)
{
int count = 0;
foreach (ListItem item in this.lbFruits.Items)
{
if (item.Selected)
{
count++;
}
}
ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('Selected option count = " + count + "')", true);
}
Screenshot