I use a ListBox in my ASP.NET Application that display Active Directory Users. Now I want use a ListView but I don’t know how I can fill it with Data 🙁
My Application:
The User input a String (Lastname or a part of this) in a TextBox. Than the ListBox list all AD Users with the same string from the TextBox. The User who use the asp.net application selected a line in the ListBox and about a Button (btn_ShowProperties) he see all Properties of this AD User.
The Code:
protected void btnBenutzerSuchen_Click(object sender, EventArgs e)
{
//lboxBenutzer is the ListBox
lboxBenutzer.Items.Clear();
DirectoryEntry Entry = new DirectoryEntry("LDAP://" + "Domain");
string filter = "(&(objectClass=user)(objectCategory=person)(cn=" + txtBenutzer.Text + "*))";
DirectorySearcher Searcher = new DirectorySearcher(Entry, filter);
foreach (SearchResult res in Searcher.FindAll())
{
//GetProperty is a Method to get the Informations from AD
string Benutzer = GetProperty(res, "sAMAccountName");
string eMail = GetProperty(res, "mail");
string Vorname = GetProperty(res, "givenName");
string Nachname = GetProperty(res, "sn");
string Telefon = GetProperty(res, "telephoneNumber");
//How I make this in a ListView? :(
lboxBenutzer.Items.Add(new ListItem(eMail + " | " + Benutzer + " | " + Nachname + ", " + Vorname + " | " + Telefon));
}
}
My Idea:
I want use a ListView because the representation of a ListBox is not the right. My Problem is it to add a line to the ListView. What can I do :/ ?
PS: Sorry for my bad English. I’m from Germany 😛
tarasov
That’s easy, a
ListViewis a databound control, therefore you can use the same binding techniques that you would use with any data-bound controls such aGridVew,FormView,ListBox, etcSince you already have an
Enumerable(based on your code:Searcher.FindAll()), then you only have to bind it:ASPX
Code to bind it, code behind
Edit 1
To add a table layout: