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(Do main.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(co mputer.Nam e)
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
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(Do
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(co
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
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
ASKER
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
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
Bob
ASKER
Hi,
No errors and not getting anything.
ayha
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(co mputer.Nam e)
End If
Bob
If computer.class = "Computer" Then
DropDownList2.Items.Add(co
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(DropDownL ist1.Selec tedItem.Te xt)
End Sub
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(DropDownL
End Sub
ASKER
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
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="DomainsAndPcsVBW eb.WebForm 1"%>
<!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_defaultClientScri pt" 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: DropDownLi st>
<asp:DropDownList id="DropDownList2" style="Z-INDEX: 103; LEFT: 288px; POSITION: absolute; TOP: 144px"
runat="server"></asp:DropD ownList>
</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.Debugg erStepThro ugh()> Private Sub InitializeComponent()
End Sub
Protected WithEvents Button1 As System.Web.UI.WebControls. Button
Protected WithEvents DropDownList1 As System.Web.UI.WebControls. DropDownLi st
Protected WithEvents DropDownList2 As System.Web.UI.WebControls. DropDownLi st
'NOTE: The following placeholder declaration is required by the Web Form Designer.
'Do not delete or move it.
Private designerPlaceholderDeclara tion 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(Do main.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(co mputer.Nam e)
End If
Next
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
PullAllDomains()
PullAllComputers(DropDownL ist1.Selec tedItem.Te xt)
End Sub
Private Sub DropDownList1_SelectedInde xChanged(B yVal sender As System.Object, ByVal e As System.EventArgs) Handles DropDownList1.SelectedInde xChanged
PullAllComputers(DropDownL ist1.Selec tedItem.Te xt)
End Sub
End Class
===========
hope it will work this time
here's the compelete project with code, try to create new project called "DomainsAndPcsVBWeb"
webform1.aspx
=========
<%@ Page Language="vb" AutoEventWireup="false" Codebehind="WebForm1.aspx.
<!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_defaultClientScri
<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:
<asp:DropDownList id="DropDownList2" style="Z-INDEX: 103; LEFT: 288px; POSITION: absolute; TOP: 144px"
runat="server"></asp:DropD
</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.Debugg
End Sub
Protected WithEvents Button1 As System.Web.UI.WebControls.
Protected WithEvents DropDownList1 As System.Web.UI.WebControls.
Protected WithEvents DropDownList2 As System.Web.UI.WebControls.
'NOTE: The following placeholder declaration is required by the Web Form Designer.
'Do not delete or move it.
Private designerPlaceholderDeclara
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(Do
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(co
End If
Next
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
PullAllDomains()
PullAllComputers(DropDownL
End Sub
Private Sub DropDownList1_SelectedInde
PullAllComputers(DropDownL
End Sub
End Class
===========
hope it will work this time
ASKER
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