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