Hi, I have a web method that returns an array, when I test the page it displays an xml results within xml as:
Can someone help me getting results in a list box by firing a button with argument/filter as txtusername from textbox
The code:
Public Function SearchName(ByVal txtUserName As String) As String() 'As List(Of String)
Dim connection As String = ConfigurationManager.ConnectionStrings("ADConnection").ToString()
Dim adSearcherObject As DirectorySearcher = New DirectorySearcher(connection)
adSearcherObject.SearchScope = SearchScope.Subtree
adSearcherObject.Filter = String.Format("(&(objectClass=user)(objectcategory=person)(cn=*{0}*))", [txtUserName])
Dim results As New List(Of String)()
For Each adObject As SearchResult In adSearcherObject.FindAll()
results.Add(adObject.Properties("cn") (0).ToString())
'results.Add(adObject.Properties("mail") (0).ToString())
results.Add(CStr(adObject.GetDirectoryEntry().Properties("mail").Value))
results.Add(CStr(adObject.GetDirectoryEntry().Properties("cn").Value))
Next
Return results.toarray()
End Function
Appreciate your support.
Thanks.
Look at example d on this thread
http://forums.asp.net/t/1934215.aspx?Using+jQuery+ajax+to+call+asmx+webservice+methods
Please excuse my little knowledge in programming, can you please give me more guidance to get the results in a lisybox?
Thanks in advance
It's in c# I'm afraid
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ListView.aspx.cs" Inherits="WebTest.ajax.ListView" %>
Thanks for your reply, now I have other question please.
need to get the returned data bound to a list box and a gridview, for both Name and Email from searched redult in LDAP of a user, and the loop below seem not working.
Please help.
Dim results As DataTable = New DataTable("SearchName")
results.columns.add("Name", gettype(string))
results.columns.add("Email", gettype(string))
results.columns.add("All", gettype(string))
...
For Each adObject As SearchResult In adSearcherObject.FindAll()
results.rows.Add(adobject.GetD
Next
Return results
thanks
hi ,
u can try to change it below:
results.rows.Add(new object(){adobject.GetDirectoryEntry().Properties("cn"), "mail", "cnmail"})
Galeny,
Thanks for the reply, however, the xml returned has no data,
here is the complete simple method
_ Public Function SearchName (ByVal txtUserName As String) As DataTable
Dim connection As String = ConfigurationManager.ConnectionStrings("ADConnection").ToString()
Dim adSearcherObject As DirectorySearcher = New DirectorySearcher(connection)
adSearcherObject.SearchScope = SearchScope.Subtree
adSearcherObject.Filter = String.Format("(&(objectClass=user)(objectcategory=person)(cn=*{0}*))", [txtUserName])
Dim results As DataTable = New DataTable("SearchName")
results.columns.add("Name", gettype(string))
results.columns.add("Email", gettype(string))
results.columns.add("All", gettype(string))
For Each adObject As SearchResult In adSearcherObject.FindAll()
results.rows.Add(new object(){adobject.GetDirectoryEntry().Properties("cn"), ("mail"), ("cn mail")}))
Next
Return results
End Function
and the xml file :
since a listbox gives just troubles, Please, how can I populate data into agrid view
thanks.
Hi AidyF,
Can you please upload the complete code with JSON serialization.
Thanks.
沒有留言:
張貼留言