MembershipUserCollection.Count Property


Gets the number of membership user objects in the collection.

Namespace:   System.Web.Security
Assembly:  System.Web.ApplicationServices (in System.Web.ApplicationServices.dll)

public int Count { get; }

Property Value

Type: System.Int32

The number of MembershipUser objects in the collection.

The following code example lists all of the users from the membership user data source, including a count of the total number of users.

<%@ Page Language="C#" %>
<%@ Import Namespace="System.Web.Security" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
<script runat="server">

MembershipUserCollection users;

public void Page_Load(object sender, EventArgs args)
  users = Membership.GetAllUsers();
  UserGrid.DataSource = users;

  NumUsers.Text = users.Count.ToString();

<html xmlns="" >
<title>Sample: User List</title>

<form id="form1" runat="server">
  <h3>User List</h3>

  Number of Users: <asp:Label id="NumUsers" runat="server" /><br />

  <asp:DataGrid id="UserGrid" runat="server"
                CellPadding="2" CellSpacing="1"
    <HeaderStyle BackColor="darkblue" ForeColor="white" />


.NET Framework
Available since 2.0
Return to top