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.

1

1 Answer 1

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();
    }
}
4
  • hi @Simon i have already try :-var users = mbr.GetAllUsers(0, int.MaxValue, out total); it returns total=9.but not displaying in gridview. Commented Feb 18, 2013 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. Commented Feb 18, 2013 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. Commented Feb 18, 2013 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; Commented Feb 18, 2013 at 10:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.