How to get the selected-row count from a list box in asp.net
<pre><code>int countSelected = ListBoxMembers.Items.Cast&lt;ListItem&gt;().Where(i =&gt; i.Selected).Count();
       string groupName = txt_GroupName.Text;


       for (int counter = 0; counter &lt; ListBoxMembers.Items.Count; counter++)
</code></pre>

<p>I have 20 items in the list, when I select only 2 ListBoxMembers.Items.Count shouws 20  and Countselected is 0</p>

<p>i tried this int count = ListBoxMembers.GetSelectedIndices().length;
system.web.ui.controls.listbox does not contain a definition for selected items and no extension method selevted items acceptin first argument error</p>

<pre><code> &lt;asp:ListBox ID="ListBoxMembers" runat="server" SelectionMode="Multiple" CssClass="style102"
                                   ToolTip="Press ctrl to select multiple users" DataValueField="FirstName"&gt;&lt;/asp:ListBox&gt;
</code></pre>
