AD Datasource for DropDown box

Discussion in 'ASP .Net' started by =?Utf-8?B?R29uem9v?=, Nov 15, 2006.

  1. 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



    --
    Lorenzo Gonzalez
    ACS/Spherion
    Lead Technical System Engineer
    =?Utf-8?B?R29uem9v?=, Nov 15, 2006
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Paul

    Datasource in a dropdown list

    Paul, Apr 27, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    344
    Scott Hamlin
    Apr 27, 2004
  2. =?Utf-8?B?TWVyZGFhZA==?=
    Replies:
    5
    Views:
    5,846
    neskire
    Nov 7, 2006
  3. =?Utf-8?B?TWVyZGFhZA==?=
    Replies:
    0
    Views:
    347
    =?Utf-8?B?TWVyZGFhZA==?=
    Oct 20, 2004
  4. Mike
    Replies:
    1
    Views:
    796
  5. Gnarlodious
    Replies:
    4
    Views:
    17,558
    elizas
    May 5, 2010
Loading...

Share This Page