New to ASP.net
New to ASP.net
New to ASP.net
New to ASP.net
New to ASP.net
New to ASP.net New to ASP.net New to ASP.net New to ASP.net New to ASP.net New to ASP.net New to ASP.net New to ASP.net
New to ASP.net New to ASP.net
New to ASP.net
Go Back  Xtreme Visual Basic Talk > > > New to ASP.net


Reply
 
Thread Tools Display Modes
  #1  
Old 06-19-2008, 07:58 AM
jagoh87 jagoh87 is offline
Regular
 
Join Date: Sep 2005
Location: Hull, Yorkshire
Posts: 90
Default New to ASP.net


My boss has asked me to take a look at creating a site that will list all the users in our AD tree.

I created a few vb .net applications doing this sort of thing so im familiar with that.

What i have so far is a dropdownlist with a button, on the form load it populates the dropdownlist with all our users.

what i then want is to click the button and to display the details(name, email etc) for the user.

This is what i have so far

Code:
Imports System.DirectoryServices
Partial Class _Default
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        getaduserlist()
        sortlistitems(DropDownList1)
    End Sub



    Public Function getaduserlist() As ArrayList
        getaduserlist = New ArrayList
        Dim DE As DirectoryEntry = New DirectoryEntry("LDAP://OU=xxxxxxxx,DC=xxxxxxxx,DC=com")
        Dim mySearcher As DirectorySearcher = New DirectorySearcher(DE)
        mySearcher.Filter = ("OU=*")
        Dim resEnt As SearchResult
        For Each resEnt In mySearcher.FindAll()
            If resEnt.GetDirectoryEntry.Name.Contains("Workstations") = False _
            AndAlso resEnt.GetDirectoryEntry.Name.Contains("Laptops") = False _
            AndAlso resEnt.GetDirectoryEntry.Name.Contains("Printers") = False _
            AndAlso resEnt.GetDirectoryEntry.Name.Contains("Groups") = False _
            AndAlso resEnt.GetDirectoryEntry.Name.Contains("Contacts") = False _
            AndAlso resEnt.GetDirectoryEntry.Name.Contains("Agents") = False _
            AndAlso resEnt.GetDirectoryEntry.Name.Contains("System") = False _
            AndAlso resEnt.GetDirectoryEntry.Name.Contains("Computers") = False Then
                Dim entry As DirectoryEntry = New DirectoryEntry(resEnt.GetDirectoryEntry.Path)
                Dim Searcher As DirectorySearcher = New DirectorySearcher(entry)
                Searcher.Filter = "(&(objectClass=user)(objectCategory=person))"
                For Each resEntry As SearchResult In Searcher.FindAll()
                    Dim de2 As DirectoryEntry = resEntry.GetDirectoryEntry
                    DropDownList1.Items.Add(de2.Properties("DisplayName").Value.ToString() & " (" & de2.Properties("samAccountName").Value.ToString & ")")
                Next
            End If
        Next
        Return getaduserlist
    End Function


    Private Sub sortlistitems(ByVal list As Object)
        Dim li As ListItem
        Dim sl As SortedList = New SortedList
        For Each li In list.items
            sl.Add(li.Text, li.Value)
        Next
        list.datasource = sl
        list.datavaluefield = "value"
        list.datatextfield = "key"
        list.databind()
    End Sub

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click

    End Sub
End Class
HTML Code:
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="contacts_home.aspx.vb" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Contacts</title>
    <style type="text/css">
        .style1
        {
            font-family: Arial, Helvetica, sans-serif;
            font-weight: bold;
            font-size: small;
        }
        .style2
        {
            width: 301px;
        }
    </style>
    </head>
<body>
    <form id="form1" runat="server">
    <div>
    
    </div>
    
    <div>
  <div align="left">
    <table>
      <tr>
        <td></td>
      </tr>
      <tr>
        <td valign="top">People
          <ul id="list-menu" style="list-style-image: &gt;">
            <li class="style1"><a href="home.aspx" target="mainFrame">Home</a></li>
            <li class="style1"><a href="search.aspx" target="mainFrame">Search</a></li>
            <li class="style1"><a href="by_department.aspx" target="mainFrame">List By Office</a></li>
            <li class="style1"><a href="by_name.aspx" target="mainFrame">List By Name</a></li>
          </ul></td>
        <td class="style2"><table width="100%">
            <tr>
              <td bgcolor="#CCCCCC"><div align="center">Quick Lookup </div></td>
            </tr>
            <tr>
              <td>
                  <div align="center" style="width: 519px"> Select User ID
                      <asp:DropDownList ID="DropDownList1" runat="server" Width="303px">
                      </asp:DropDownList>
                      &nbsp;&nbsp;
                      <asp:Button ID="Button1" runat="server" Text="Look Up" Width="79px" />
                  </div>
                                    </td>
            </tr>
            
          </table></td>
        <td>&nbsp;</td>
      </tr>
    </table>
  </div>
</div>
    </form>
    
    </body>
</html>
Any help in guiding me on how to do this would be great
Reply With Quote
  #2  
Old 06-24-2008, 12:57 PM
lebb's Avatar
lebbNew to ASP.net lebb is offline
Disillusioned Code Poet

Retired Moderator
* Guru *
 
Join Date: Apr 2002
Location: Tennessee, USA
Posts: 12,808
Default

First off, Page_Load is going to fire every time your page is loaded, including when the button is clicked (before its Click event fires). So you'll want to move your code there inside an If Not IsPostBack block so that it only runs the first time the page is loaded.

Next, I'd recommend adding a panel to your page (you can do that in the designer or code the HTML directly), then drag labels or textboxes onto it for the detail display you want. Set the panel's Visible property to False. Then in your button's Click event handler, you can populate those controls and show the panel by setting its Visible property back to true.
__________________
Laura

Ita erat quando hic adveni.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
New to ASP.net
New to ASP.net
New to ASP.net New to ASP.net
New to ASP.net
New to ASP.net
New to ASP.net New to ASP.net New to ASP.net New to ASP.net New to ASP.net New to ASP.net New to ASP.net
New to ASP.net
New to ASP.net
 
New to ASP.net
New to ASP.net
 
-->