Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8266065
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T05:01:23+00:00 2026-06-08T05:01:23+00:00

I use a ListBox in my ASP.NET Application that display Active Directory Users. Now

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T05:01:25+00:00Added an answer on June 8, 2026 at 5:01 am

    That’s easy, a ListView is a databound control, therefore you can use the same binding techniques that you would use with any data-bound controls such a GridVew, FormView, ListBox, etc

    Since you already have an Enumerable (based on your code: Searcher.FindAll()), then you only have to bind it:

    ASPX

    <asp:ListView runat="server" ID="myListView">
        <ItemTemplate>
            <asp:Label ID="Label1" Text='<%# Eval("Benutzer") %>' runat="server" /><br />
            <asp:Label ID="Label2" Text='<%# Eval("eMail") %>' runat="server" /><br />
            <asp:Label ID="Label3" Text='<%# Eval("Vorname") %>' runat="server" /><br />
            <asp:Label ID="Label4" Text='<%# Eval("Nachname") %>' runat="server" /><br />
            <asp:Label ID="Label5" Text='<%# Eval("Telefon") %>' runat="server" /><br />
        </ItemTemplate>
        <ItemSeparatorTemplate>
            <hr />
        </ItemSeparatorTemplate>
    </asp:ListView>
    

    Code to bind it, code behind

    var q = from s in Searcher.FindAll().OfType<SearchResult>()
            select new
            {
                Benutzer = GetProperty(s, "sAMAccountName"),
                eMail = GetProperty(s, "mail"),
                Vorname = GetProperty(s, "givenName"),
                Nachname = GetProperty(s, "sn"),
                Telefon = GetProperty(s, "telephoneNumber")
            };
    
    this.myListView.DataSource = q;
    this.myListView.DataBind();
    

    Edit 1

    To add a table layout:

        <asp:ListView runat="server" ID="myListView">
            <LayoutTemplate>
                <table runat="server" border="1">
                    <tr runat="server">
                        <th runat="server">Benutzer</th>
                        <th runat="server">eMail</th>
                        <th runat="server">Vorname</th>
                        <th runat="server">Nachname</th>
                        <th runat="server">Telefon</th>
                    </tr>
                    <tr runat="server" id="ItemPlaceholder">
                    </tr>
                </table>
            </LayoutTemplate>
            <ItemTemplate>
                <tr runat="server">
                    <td runat="server"><%# Eval("Benutzer")%></td>
                    <td runat="server"><%# Eval("eMail")%></td>
                    <td runat="server"><%# Eval("Vorname")%></td>
                    <td runat="server"><%# Eval("Nachname")%></td>
                    <td runat="server"><%# Eval("Telefon")%></td>
                </tr>
            </ItemTemplate>
        </asp:ListView>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Now I am aware that I probably need to use a ListBox and can
I use SendMessage(hList, LB_SETITEMDATA, pos, (LPARAM) data ); for adding names to listbox. But
I am a newbie to ASP.NET MVC (v2), and I am trying to use
I use listbox.ScrollIntoView(item), but as long as this item is in listbox view, it
Can I use ListBox control in MS CRM? I want to scroll the list
Lets say I have a WPF application that shows a ListBox with an ArrayList
At my work we have an existing ASP.NET web application and are duplicating some
I have some items populated in the listbox from the database in my asp.net
I recently was assigned to update an old project who use the asp:listbox control
in ASP.NET, I've bound a listbox control to a List of custom class (consisting

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.