Explanation:
First we are creating the MembershipUserCollection Object and Filling it with All Registered users using Membership Object GetAllUsers(); method.
For creating the Sorted list we need a DataView Object which will be created through Filling a DataTable from all users data.
public DataView GetAllUsersDataTable()
{
MembershipUserCollection mc = new MembershipUserCollection();
mc = Membership.GetAllUsers();
DataTable dt = new DataTable("LastUsers");
dt.Columns.Add("UserName", typeof(string));
dt.Columns.Add("Rdate", typeof(DateTime));
foreach (MembershipUser st in mc)
{
dt.Rows.Add(new Object[] { st.UserName, st.CreationDate });
}
dt.AcceptChanges();
DataView dv = new DataView(dt);
return dv;
}
Now we will sort the DataView on users Registration data. (Descended i.e last registered 1st)
DataView tView = GetAllUsersDataTable();
tView.Sort = "Rdate DESC";
GridView1.DataSource = tView;
GridView1.DataBind();
|