G. M. Nazmul Hossain
G. M. Nazmul Hossain

Reputation: 466

How to show roles in ASP.NET?

I am getting user list using Membership.GetAllUsers() function. And I bind this data in a grid view.

But I cannot find the roles information here. I need to show the roles in that grid view.

What should I do ?

Upvotes: 1

Views: 1308

Answers (2)

djeeg
djeeg

Reputation: 6765

Roles.GetRolesForUser(user)

http://msdn.microsoft.com/en-us/library/8h930x07.aspx

UPDATE

This is going to be pretty slow if you have a lot of users

GridView.RowDataBound += new GridViewRowEventHandler(GridView_RowDataBound);

void GridView_RowDataBound(object sender, GridViewRowEventArgs e) {
    GridView gridview = (GridView)sender;
    if (e.Row.RowType == DataControlRowType.DataRow) {
        string username = DataBinder.Eval(e.Row.DataItem, "yourusernamecolumn").ToString();
        Literal c = new Literal();
        c.Text = Roles.GetRolesForUser(username).ToString(); //decide how you want to display the list
        e.Row.Cells[somecolumnindex].Controls.Add(c);
    }
}

It might be better to read straight from your role-to-member table.

Upvotes: 1

Emond
Emond

Reputation: 50672

Use RoleProvider.GetAllRoles().

Upvotes: 0

Related Questions