0

i have multiple membership providers in my asp.net application. i have access membership provider by using code:-

MembershipProvider mbr;
mbr = Membership.Providers["CustomMembershipProvider"];

I want to fetch all users and display in grid view. How i can i do this.

Sani Huttunen
  • 23,620
  • 6
  • 72
  • 79
Umesh Sehta
  • 10,555
  • 5
  • 39
  • 68
  • possible duplicate of [How to Get List of User/Profile from Membership Provider?](http://stackoverflow.com/questions/920533/how-to-get-list-of-user-profile-from-membership-provider) – Sani Huttunen Feb 18 '13 at 10:18

1 Answers1

0

You can use the MembershipProvider.GetAllUsers Method:

int total;
var users = mbr.GetAllUsers(0, int.MaxValue, out total);

or pass an index and page size if you have a paging grid.

And here an ASPX fragment defining the gridview:

<asp:GridView runat="server" ID="GV"></asp:GridView>

And the corresponding code-behind C# class:

public partial class MyPage : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        // create membership instance...
        int total;
        GV.DataSource = mbr.GetAllUsers(0, int.MaxValue, out total);
        GV.DataBind();
    }
}
Simon Mourier
  • 132,049
  • 21
  • 248
  • 298
  • hi @Simon i have already try :-var users = mbr.GetAllUsers(0, int.MaxValue, out total); it returns total=9.but not displaying in gridview. – Umesh Sehta Feb 18 '13 at 10:19
  • @MohitArora: Then your question is all wrong. You don't need help with getting a list of users from a MembershipProvider. What you REALLY want help with is "How to display a collection in a grid". Please delete the question and google for the answer. – Sani Huttunen Feb 18 '13 at 10:28
  • If you cannot find anything relevant then search SO for the answer. If you still can't find any relevant information, write a new question specifying what you REALLY want help with. – Sani Huttunen Feb 18 '13 at 10:31
  • hi @SimonMourier thanks its working. i know how to bind grid view but user list count was 0 in membershipuserproviders but when i move the cursor on total by using breakpoint its showing 0 i.e out total=9; – Umesh Sehta Feb 18 '13 at 10:39