views:

217

answers:

2

Hello,

I want to creating my own paging control and I would like to use it to list users in a grid.

Somehow I need to get only the top 10 for example users for the first page and then 10-20 users and so on.

I can't find any built in methods in the membership namespace. Finduserbyname is useful if I want to find all the users whose username starts for example with A or whatever.

Now I need a efficient way to pull these data on a page by page basis.

Thank you

A: 

Hi...I found an article that shows how to use the Membership.GetAllUsers(); function and then use that as a datasource

So, you have a gridview or data grid and set the source like so:

Users.DataSource = Membership.GetAllUsers();
Users.DataBind();

and then you can create your paging from there (or using built in paging from gridview)

chad
Or you can use the PagedDataSource object. Very handy.
Spencer Ruport
There is an overload method which defined more parameter for paging purposes http://msdn.microsoft.com/en-us/library/system.web.security.membership.findusersbyname.aspx . The weakness of using GetAllUsers() is the paging is performed at the application level, not at database level. While you query All data from the database, we only use a subset of it at the application level. It will be better if we invoke the correct parameter, so that the API can perform paging right down to the database level, to conserve the resource
hadi teo
+2  A: 

Hi Raha

When i googled the method definition Membership.FindUsersByName, it has more parameters which can be used to defined Paging

Here is the details : http://msdn.microsoft.com/en-us/library/fa5st8b2.aspx

public static MembershipUserCollection FindUsersByName(
 string usernameToMatch,
 int pageIndex,
 int pageSize,
 out int totalRecords
)

As you can see from the parameter definition, you can supply the (int) pageIndex, as well as the (int) pageSize.

so let's say you have a total of 100 records which qualified the users with firstname='John', then if you would like to retrieve the 1st page (with a total of 10 users in each page), you can set the (int) pageIndex to 1, and then the (int) pageSize to 10.

Subsequently if you want to retrieve the 2nd page, you can define the (int) pageIndex to 2 and (int) pageSize to 10.

You can utilize the totalRecords (out) parameter, to obtain how many total number of records , so that you can use this to display in your UI Grid.

hadi teo