Binding AD users to Drop down

Binding AD users to Drop down

Post by David » Sat, 28 Jun 2003 00:24:38



I am tring to the usernames in the users container to a
drop down list.  If I use Response.Write(result.Properties
("CN")(0) & "<Br>"), I can see the usernames, but I can't
figure out how to bind the list to a drop down.  Any help
is appreciated!

Dim entry As New DirectoryEntry
("LDAP://internal.bwater.com/CN=Users, DC=mycompany,
DC=com", "username", "passowrd")

        Dim mySearcher As New DirectorySearcher(entry)
        mySearcher.PropertiesToLoad.Add("CN")
        Dim results As SearchResultCollection =    
        mySearcher.FindAll()
        Dim result As SearchResult

        For Each result In results
            ddUsers.DataSource = result.Properties("CN")
            ddUsers.DataTextField = "CN"
            ddUsers.DataBind()

        Next result

 
 
 

Binding AD users to Drop down

Post by MVP - ADS » Sat, 28 Jun 2003 03:39:37


My suggestion would be to also retrieve the distinguishedName of the user in
addition to their common.  Given the distinguishedName, you can bind to the
user object directly.

The thing I'm not totally clear about is how to use whatever databound web
control you are using so that it does some kind of a key-value pair type of
thing.  I'm sure there's an easy way to do that, but I'm not sure what that
is.  However, you can cheat and just load the CN and distinguishedName into
a HashTable or StringDictionary (better yet) and use that to retrieve the
DN.

So, start with:

mySearcher.PropertiesToLoad.Add("distinguishedName")

and go from there.  Your binding string for your DirectoryEntry will be
something like:

"LDAP://internal.bwater.com/" &
DirectCast(result.Properties("distinguishedName")(0), System.String)

I hope that helps.

Joe K.


Quote:

> I am tring to the usernames in the users container to a
> drop down list.  If I use Response.Write(result.Properties
> ("CN")(0) & "<Br>"), I can see the usernames, but I can't
> figure out how to bind the list to a drop down.  Any help
> is appreciated!

> Dim entry As New DirectoryEntry
> ("LDAP://internal.bwater.com/CN=Users, DC=mycompany,
> DC=com", "username", "passowrd")

>         Dim mySearcher As New DirectorySearcher(entry)
>         mySearcher.PropertiesToLoad.Add("CN")
>         Dim results As SearchResultCollection =
>         mySearcher.FindAll()
>         Dim result As SearchResult

>         For Each result In results
>             ddUsers.DataSource = result.Properties("CN")
>             ddUsers.DataTextField = "CN"
>             ddUsers.DataBind()

>         Next result