Link to home
Start Free TrialLog in
Avatar of ayha1999
ayha1999

asked on

Populating two DDLs

Hi,

the following functions populates all domain names in the dropdownlist1 and all computer names in the dropdownlist2.

Sub PullAllDomains()
        Dim objNameSpace
        Dim Domain
        objNameSpace = GetObject("WinNT:")
        For Each Domain In objNameSpace
            DropDownList1.Items.Add(Domain.Name)
        Next
    End Sub

    Sub PullAllComputers(ByVal strDomain)
        Dim PrimDomainContr
        PrimDomainContr = GetObject("WinNT://" & strDomain)
        Dim computer
        For Each computer In PrimDomainContr
            If computer.class = "Computer" Then
                DropDownList2.Items.Add(computer.Name)
            End If
        Next
    End Sub

How can I populate dropdownlist2 with computer names for the selected domain name in the dropdownlist1?

could anyone pls. help me?

ayha
ASKER CERTIFIED SOLUTION
Avatar of Mohammed Nasman
Mohammed Nasman
Flag of Palestine, State of image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ayha1999
ayha1999

ASKER

HI nasman,

I get the first ddl popoulated with domains but when I change selection I don't get the second ddl populated.

could u pls. check if something wrong?

Our domain is Windows 2003.

ayha
Hi ayha

Have you changed the AutoPostBack property of the first dll to true?

  I Created new project and test the code again, and it's working fine too, we have 3 domain with windows 2000, but it should be the same with 2003

regards,
Mohammed
Hi mnasman,

AutoPostBack is set to true still I dont get the second DDL populated with computers names when I change the first DDL.

I can browse the domain and computers through Network Neighborhood (Microsoft Networks) on the desktop.

What u think could be wrong?

ayha

Are you getting anything in the second DDL?  Are there any errors?

Bob
Hi,

No errors and not getting anything.

ayha
Are you getting any instances of computer?  And, is the Items.Add line reached in this block?

           If computer.class = "Computer" Then
                DropDownList2.Items.Add(computer.Name)
            End If

Bob
mmm, I just retest it again and find a thing

if you have one domain only, the SelectedIndexChanged will not fire, so you could try to fire it after you fill the first dll

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        PullAllDomains()
        PullAllComputers(DropDownList1.SelectedItem.Text)
    End Sub
Hi mnasman,

I get 8 domains names popoulated in the first DDL when page loads, not only one.

when I browse the network neighborhood, I can see all these domains when I open Microsft Networks and many computers in each domain but when I open Directory I can see only one domain and when I open that no computers in it.

ayha
We have 3 domains in our network, and code working with them

here's the compelete project with code, try to create new project called "DomainsAndPcsVBWeb"

webform1.aspx
=========
<%@ Page Language="vb" AutoEventWireup="false" Codebehind="WebForm1.aspx.vb" Inherits="DomainsAndPcsVBWeb.WebForm1"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
      <HEAD>
            <title>WebForm1</title>
            <meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
            <meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1">
            <meta name="vs_defaultClientScript" content="JavaScript">
            <meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
      </HEAD>
      <body MS_POSITIONING="GridLayout">
            <form id="Form1" method="post" runat="server">
                  <asp:Button id="Button1" style="Z-INDEX: 101; LEFT: 416px; POSITION: absolute; TOP: 200px" runat="server"
                        Text="Button"></asp:Button>
                  <asp:DropDownList id="DropDownList1" style="Z-INDEX: 102; LEFT: 288px; POSITION: absolute; TOP: 112px"
                        runat="server" AutoPostBack="True"></asp:DropDownList>
                  <asp:DropDownList id="DropDownList2" style="Z-INDEX: 103; LEFT: 288px; POSITION: absolute; TOP: 144px"
                        runat="server"></asp:DropDownList>
            </form>
      </body>
</HTML>
===========================================


webform.aspx.vb
=======

Public Class WebForm1
    Inherits System.Web.UI.Page

#Region " Web Form Designer Generated Code "

    'This call is required by the Web Form Designer.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

    End Sub
    Protected WithEvents Button1 As System.Web.UI.WebControls.Button
    Protected WithEvents DropDownList1 As System.Web.UI.WebControls.DropDownList
    Protected WithEvents DropDownList2 As System.Web.UI.WebControls.DropDownList

    'NOTE: The following placeholder declaration is required by the Web Form Designer.
    'Do not delete or move it.
    Private designerPlaceholderDeclaration As System.Object

    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
        'CODEGEN: This method call is required by the Web Form Designer
        'Do not modify it using the code editor.
        InitializeComponent()
    End Sub

#End Region

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Put user code to initialize the page here
    End Sub

    Sub PullAllDomains()
        DropDownList1.Items.Clear()
        Dim objNameSpace
        Dim Domain
        objNameSpace = GetObject("WinNT:")
        For Each Domain In objNameSpace
            DropDownList1.Items.Add(Domain.Name)
        Next
    End Sub
    Sub PullAllComputers(ByVal strDomain)
        DropDownList2.Items.Clear()
        Dim PrimDomainContr
        PrimDomainContr = GetObject("WinNT://" & strDomain)
        Dim computer
        For Each computer In PrimDomainContr
            If computer.class = "Computer" Then
                DropDownList2.Items.Add(computer.Name)
            End If
        Next
    End Sub
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        PullAllDomains()
        PullAllComputers(DropDownList1.SelectedItem.Text)
    End Sub

    Private Sub DropDownList1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged
        PullAllComputers(DropDownList1.SelectedItem.Text)
    End Sub

End Class


===========

hope it will work this time