• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 313
  • Last Modified:

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
0
ayha1999
Asked:
ayha1999
  • 4
  • 4
  • 2
1 Solution
 
Mohammed NasmanSoftware DeveloperCommented:
Hi Ayha

  Set the AutoPostback property of DropDownList1 to true, and write the code to Fill dropdownlist2 with computers in domain in SelectedIndexChanged event of DropDownList

Here's the complete sample
============

    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()
    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
=========

Best regards,
Mohammed Nasman
0
 
ayha1999Author Commented:
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
0
 
Mohammed NasmanSoftware DeveloperCommented:
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
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
ayha1999Author Commented:
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

0
 
Bob LearnedCommented:
Are you getting anything in the second DDL?  Are there any errors?

Bob
0
 
ayha1999Author Commented:
Hi,

No errors and not getting anything.

ayha
0
 
Bob LearnedCommented:
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
0
 
Mohammed NasmanSoftware DeveloperCommented:
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
0
 
ayha1999Author Commented:
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
0
 
Mohammed NasmanSoftware DeveloperCommented:
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
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 4
  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now