Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Professional
|
ASP.NET 2.0 Professional If you are an experienced ASP.NET programmer, this is the forum for your 2.0 questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 4th, 2006, 04:20 PM
saf saf is offline
Authorized User
 
Join Date: Nov 2006
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you so much. Works like a charm. Only thing I am trying to do now is only select certain usernames. I put a usertype field in the aspnetdb users table and want to select only usernames that have this value set. Am I going in the right direction? I assume I need some sort of custom paramerter for the getallusers method.
Your help is GREATLY appreciated.



 
Old December 4th, 2006, 04:46 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Unfortunately, that is not supported out of the box.

One easy way to do this is to put those users in a specific group and then change the call to Membership.GetAllUsers()

to

Roles.GetUsersInRole(roleName)

That gives you a list of the users in the specified role.

Otherwise, you need to create a custom method that returns a MembershipCollection. Inside this method you could fire a custom stored procedure that returns the users based on your criteria. You can take a look at the standard stored procedures and at the code for the standard SQL providers for some ideas on how to do this.

Cheers,

Imar
---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
Want to be my colleague? Then check out this post.
 
Old December 5th, 2006, 02:49 PM
saf saf is offline
Authorized User
 
Join Date: Nov 2006
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
Default

One last time for a newbie....

I do have all my users that I want to display in a Role (rolename ="Members"), just need a bit more explanation on how to configure the objectdatasource to show all users in role Members...

I changes ODS TypeName to System.Web.Security.Roles, the SelectMethod to GetUsersInRole(StringRolename,returns String[]) and set parameters as follows
<asp:Parameter DefaultValue="Members" Name="roleName" Type="String" />

Am I completely off track...

Once again, thanks in advance for all your help
{

 
Old December 5th, 2006, 06:35 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Close, but no cigar.... ;)

Here's what you should do:
Code:
<asp:ObjectDataSource ID="ObjectDataSource1" 
       runat="server" SelectMethod="GetUsersInRole" 
       TypeName="System.Web.Security.Roles">
  <SelectParameters>
    <asp:Parameter DefaultValue="Members" Name="roleName" /> 
  </SelectParameters>
</asp:ObjectDataSource>
Since GetUsersInRole() returns an array of Strings, you don't need to specify the DataValueField and DataKeyField in the dropdown:
Code:
<asp:DropDownList ID="DropDownList1" runat="server" 
        DataSourceID="ObjectDataSource1">
</asp:DropDownList>
Hope this helps,

Imar
---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
Want to be my colleague? Then check out this post.
 
Old December 5th, 2006, 07:07 PM
saf saf is offline
Authorized User
 
Join Date: Nov 2006
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
Default

You make it seem so easy. Thank you - Thank You - Thank You!
You save me hours of frustration....
saf

 
Old December 6th, 2006, 08:30 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

You're welcome. Glad I could help.

In case anyone else is interested in the full solution, I wrote a short article about it here: http://Imar.Spaanjaars.Com/QuickDocId.aspx?quickdoc=409

Cheers,

Imar
---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
While typing this post, I was listening to: Ivo by Cocteau Twins (Track 1 from the album: Treasure) What's This?





Similar Threads
Thread Thread Starter Forum Replies Last Post
User Accounts ASPNET.mdf pschulz ASP.NET 2.0 Basics 3 June 19th, 2008 12:41 PM
Users with accounts PankajGarg10 General .NET 0 April 13th, 2007 01:06 AM
Blocking user accounts Ben Horne Forum and Wrox.com Feedback 10 April 29th, 2004 10:19 PM
Accounts RM82 BOOK: ASP.NET Website Programming Problem-Design-Solution 2 April 7th, 2004 09:37 PM
Enums for accounts??? rcarter BOOK: ASP.NET Website Programming Problem-Design-Solution 3 November 8th, 2003 12:07 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.