I'm trying to put together a custom user update page so you can update a user's email, password and role all on one page. I'm stuck on the roles. I have listed the roles ok, but I want to select the role allocated to the user in a listbox.
In this case each user will only have one role.
I've tried playing around with Roles.GetRolesForUser("userName");
without much luck.
Here's the listbox code:
<asp:ListBox ID="myRoles" runat="server"
SelectionMode="Single" >
</asp:ListBox>
And here's the databinding for the Listbox:
rolesArray = Roles.GetAllRoles();
myRoles.DataSource = rolesArray;
myRoles.DataBind();
What's the easiest to get this to work?
Then in your html:
Single Role/Single Selection Only
Change loop to :
Alternatives
Here's a shorter version of that loop using LINQ to Objects:
And finally a pure LINQ mode that is in my opinion a bit too hard to read: