开发者

How to show roles in ASP.NET?

I am getting user list usi开发者_如何学Pythonng 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 ?


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.


Use RoleProvider.GetAllRoles().

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜