1
Vote

Membership provider doesn't support paged list

description

When binding the list of users to something like a GridView, one may not want to display all users at the same time (if it's a long list). That's where this function comes in:
 
MembershipUserCollection FindUsersByName(string usernameToMatch, int pageIndex, int pageSize, out int totalRecords)
 
Any provider should allow the user to input a page size and the page to return, that way the GridView is only populated with a subset of users. I've set up my website to have Next and Prev links to cycle through the pages. However, I found that the XmlMembershipProvider does not properly handle these parameters, and always returns the full list of users. I've easily corrected this on my website, but you may want to update it for whenever your next planned release is.
 
The return statement could be updated to look something like this:
 
              totalRecords = matchingUsers.Count;
              int StartIndex = pageIndex * pageSize;
              int RangeCount = ((StartIndex + pageSize) < totalRecords) ? pageSize : (totalRecords - StartIndex);
              return CreateMembershipCollectionFromInternalList(matchingUsers.GetRange(StartIndex, RangeCount));

comments