Listbox filled with Names and Surnames from AD (ASP.NET 2.0)

M

Mantvydas

Hello,

I'm creating an intranet site here.

And I'm searching the whole net, how to have a scrollable listbox full of AD
names and surnames taken from AD branches I specify in the code. The result
of a listbox should be a string "name surname", which is selected.

I can't find the answer. Maybe you could help?

Regards,
Mantvydas
 
J

Jan Peter Stotz

Mantvydas said:
And I'm searching the whole net, how to have a scrollable listbox full of AD
names and surnames taken from AD branches I specify in the code. The result
of a listbox should be a string "name surname", which is selected.

I am still developing with ASP.net 1.1 and the example code (vb.net) is for
a custom DropDownList but it should be easy to make it a ListBox.
It loads the description of several AD entries.
You can customize the DirectorySearche filter by setting the
"FilterDepartment" property.

Namespace MyCustomControls
Public Class TemplateDropDownList : Inherits DropDownList

Protected _FilterDepartment as String = ""

Protected Overrides Sub OnInit(ByVal e As EventArgs)
MyBase.OnInit(e)
UpdateItems
End Sub

Protected Sub UpdateItems
Items.Clear
Items.Add(New ListItem("Please Select Template",""))

Dim ds As New DirectorySearcher()
ds.Sort.PropertyName = "description"

ds.Filter = "(&(objectClass=user)(objectCategory=person)"+ _
FilterDepartment +")"

ds.PropertiesToLoad.Add("displayName")
Dim results As SearchResultCollection = ds.FindAll()

Dim result As SearchResult
Try
For Each result In results
Dim name As String = result.Properties("displayName")(0)
Dim path as String = result.Path
Dim li as new ListItem(name,path)
Items.Add(li)
Next
Catch e as Exception
End Try
End Sub

Public Property FilterDepartment as String
Get
return _FilterDepartment
End Get
Set
_FilterDepartment = Value.Trim
UpdateItems
End Set
End Property

End Class
End Namespace

Compile it into an assembly and place it in the bin-directory of your
project. In the aspx.Page use:

<%@ Register TagPrefix="mycontrol" Namespace="MyCustomControls"
Assembly="<assemblyname>" %>

<mycontrol:TemplateDropDownList id="mycontrol" runat="server"/>

Jan
 

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

Members online

No members online now.

Forum statistics

Threads
474,141
Messages
2,570,817
Members
47,364
Latest member
Stevanida

Latest Threads

Top