AD Datasource for DropDown box


G

Guest

I am trying to populate a drop down box with the query of users from Active
Directory. The query is working fine but the data that shows up in the
dropdown box is "System.DirectoryServices.Searchreult". Here is the code:
Anys suggestions anyone?

Protected Sub btnFindUser_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles btnFindUser.Click
Dim objRootDSE As New DirectoryEntry("LDAP://RootDSE")
Dim rootString As New String("LDAP://" +
objRootDSE.Properties("defaultNamingContext").Value)
Dim root As New DirectoryEntry(rootString)
Dim objSearch As New DirectorySearcher(root)
Dim oResults As SearchResultCollection
Dim oresult As SearchResult

Try
objSearch.Filter = "(&(objectCategory=Person)(sn=" +
txtLastName.Text + "))"
objSearch.PropertiesToLoad.Add("ADsPath")
objSearch.PropertiesToLoad.Add("displayName")
oResults = objSearch.FindAll()
lblresultsCount.Text = oResults.Count

drpUsersFound.DataSource = oResults
drpUsersFound.DataBind()

For Each oresult In oResults
If Not oresult.GetDirectoryEntry().Properties("cn").Value =
"" Then
drpUsersFound.DataValueField =
oresult.GetDirectoryEntry().Properties("adspath").Value
Dim temp1 As String = oresult.Properties("adsPath")(0)
Dim temp2 As String = oresult.Properties("displayName")(0)
drpUsersFound.DataTextField =
oresult.GetDirectoryEntry().Properties("displayname").Value
lblName.Text =
oresult.GetDirectoryEntry().Properties("displayname").Value

End If
Next
drpUsersFound.Visible = True
Label2.Visible = True

Catch ex As Exception
Console.WriteLine("the error is " + ex.ToString())
End Try
End Sub

End Class
 
Ad

Advertisements


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top