View Single Post
  #10 (permalink)  
Old December 2nd, 2006, 09:14 AM
Imar's Avatar
Imar Imar is offline
Wrox Author
Points: 72,073, Level: 100
Points: 72,073, Level: 100 Points: 72,073, Level: 100 Points: 72,073, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,587 Times in 1,563 Posts

Hi saf,

If I understand you correctly, this can be done, and it isn't too hard. Here's what you should do:

1. Add a Login control to the page and convert it to a template (on its Task pane)

2. Hide the table cell that holds the UserName textbox using runat="server" and visible="false". The login control checks to see if there is a UserName so you can't remove it, but hiding does the trick.

3. Add a new table cell to replace the text box and add a drop down control.

4. Add an ObjectDataSource control with its TypeName set to System.Web.Security.Membership, its SelectMethod to GetAllUsers and its DataObjectTypeName set to MembershipUser.

5. Hook up the DropDownList to the ObjectDataSource control by setting the DataSourceID to the ID of the ODS and set both DataTextField and DataValueField to UserName.

6. When you now run the page, you get a nice drop down list with all the user names in the system, instead of the original user name textbox.

7. The final step is to fill the UserName property of the Login control with the selected value of the dropdown list. You can do this in the LoggingIn event of the Login control. You need to "find" the DropDownList and then cast it properly, retrieve its SelectedValue and assign it to the UserName of the Login.

This way, a user can select a name from the drop down. When they click the Login button, the selected user is passed to the authentication process.

You'll find the relevant bits of code below.

Hope this helps.....

[ODS control in the Login page]
<asp:ObjectDataSource ID="ObjectDataSource1" 
  DataObjectTypeName="MembershipUser" runat="server" 
[Login control with DDL and hidden text box]
  <td align="right">
    <asp:Label ID="UserNameLabel" runat="server" 
        AssociatedControlID="UserName">User Name:</asp:Label>
  <td runat="server" visible="false">
    <asp:TextBox ID="UserName" runat="server"></asp:TextBox>
    <asp:RequiredFieldValidator ID="UserNameRequired" runat="server" 
        ControlToValidate="UserName" ErrorMessage="User Name is 
             required." ToolTip="User Name is required."
    <asp:DropDownList ID="DropDownList1" runat="server" 
       DataSourceID="ObjectDataSource1" DataTextField="UserName"
[The LoggingIn event of the Login control]
Protected Sub Login1_LoggingIn(ByVal sender As Object, _
      ByVal e As System.Web.UI.WebControls.LoginCancelEventArgs) _
      Handles Login1.LoggingIn
  Login1.UserName = CType(Login1.FindControl("DropDownList1"), DropDownList).SelectedValue
End Sub
Please let me know if this works for you.


Imar Spaanjaars
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.