The below query will pull all active users from a specific role ("administrator" in my example). The query is written on top of Membership and Authentication schema provided by ASP.NET.
My enviornment: VS2008 Beta 2.
LinqClasses.ServiceProviderDataContext context = new LNMT.LinqClasses.ServiceProviderDataContext();
var list = from s in context.aspnet_Users
join userMem in context.aspnet_Memberships on s.UserId equals userMem.UserId
join userRole in context.aspnet_UsersInRoles on s.UserId equals userRole.UserId
join roleMas in context.aspnet_Roles on userRole.RoleId equals roleMas.RoleId
where userMem.IsLockedOut == false && userMem.IsApproved == true && roleMas.LoweredRoleName == "administrator"
orderby s.UserName
select new { s.UserId, s.UserName };
//Binding to Dropdown list
DropDownList1.DataSource = list;
DropDownList1.DataValueField = "UserId";
DropDownList1.DataTextField = "UserName";
DropDownList1.DataBind();
DropDownList1.Items.Insert(0, "All"); // will insert All at the top of the list.
DropDownList1.AutoPostBack = true; // this is if you need to reload the page on change.
This is based on join statement on standard tables provided by ASP.NET Role and Membership. Hope will be useful for some.
Thanks,
Chintu
This is the first blog I am writing.. I have promised myself that I will keep doing it.. lets see. Since I have too much time @ hand :) I am trying to learn new things every day (technical stuff). I will keep typing things that I think are interesting and not easily searchable (including code snippets).. it may help someone.
Subscribe to:
Post Comments (Atom)
Welcome to my blog
Well.. its been a while I have been thinking about writing.. not on a particular topic but just random topics, share some experience and stuff like that.
You will get totally random information.. some will be to your liking and some may not be..
Dont forget to provide feedback on my posts.. even if they are crappy :)
You will get totally random information.. some will be to your liking and some may not be..
Dont forget to provide feedback on my posts.. even if they are crappy :)
No comments:
Post a Comment