473,385 Members | 2,015 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Dynamic drop down list

I hope this is the right group. I am very new to ASP so this is
probably a stupid question. I have some vbscript that query's AD and
populates a recordset. I know the recorset contains the information I
want by doing a Response.write. I am having problems dynamically
creating a drop down list from the data in the recordset. The drop down
is created but it is empty. Any help would be greatly appreciated. A
sample of the code:

<%
'On Error Resume Next
Set objRootDSE = GetObject("LDAP://RootDSE")
strDNSDomain = objRootDSE.Get("defaultNamingContext")
strOU = "OU=Generic Accounts,"
' Use ADO to search Active Directory.
Set objCommand = CreateObject("ADODB.Command")
Set objConnection = CreateObject("ADODB.Connection")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
objCommand.ActiveConnection = objConnection
strBase = "<LDAP://" & strOU &" " & strDNSDomain &">"
strFilter = "(&(objectCategory=person)(objectClass=user))"
strQuery = strBase & ";" & strFilter & ";cn;subtree"
objCommand.CommandText = strQuery
objCommand.Properties("Page Size") = 100
objCommand.Properties("Timeout") = 30
objCommand.Properties("Cache Results") = False
Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst
Do Until objRecordSet.EOF
sName = objRecordSet.Fields("cn").Value
'Response.Write(sName)
genericAccount = "<option value= & '"sName"' & >"

objRecordSet.MoveNext
Loop
%>
<html><head><title>Dynamic Drop-Down Menu Example</title></head>
<body>
<form method="POST" action="test3.asp">
<p><select size="1" name="GenericAccounts">
<%=genericAccount%>
</select></p>
</form>
</body>
</html>

Aug 28 '06 #1
6 8272
genericAccount = "<option value= & '"sName"' & >"

I would think should be

genericAccount = genericAccount & "<option value='" & sName & "'>" & sName &
"</option>"

<mc************@gmail.comwrote in message
news:11**********************@74g2000cwt.googlegro ups.com...
I hope this is the right group. I am very new to ASP so this is
probably a stupid question. I have some vbscript that query's AD and
populates a recordset. I know the recorset contains the information I
want by doing a Response.write. I am having problems dynamically
creating a drop down list from the data in the recordset. The drop down
is created but it is empty. Any help would be greatly appreciated. A
sample of the code:

<%
'On Error Resume Next
Set objRootDSE = GetObject("LDAP://RootDSE")
strDNSDomain = objRootDSE.Get("defaultNamingContext")
strOU = "OU=Generic Accounts,"
' Use ADO to search Active Directory.
Set objCommand = CreateObject("ADODB.Command")
Set objConnection = CreateObject("ADODB.Connection")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
objCommand.ActiveConnection = objConnection
strBase = "<LDAP://" & strOU &" " & strDNSDomain &">"
strFilter = "(&(objectCategory=person)(objectClass=user))"
strQuery = strBase & ";" & strFilter & ";cn;subtree"
objCommand.CommandText = strQuery
objCommand.Properties("Page Size") = 100
objCommand.Properties("Timeout") = 30
objCommand.Properties("Cache Results") = False
Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst
Do Until objRecordSet.EOF
sName = objRecordSet.Fields("cn").Value
'Response.Write(sName)
genericAccount = "<option value= & '"sName"' & >"

objRecordSet.MoveNext
Loop
%>
<html><head><title>Dynamic Drop-Down Menu Example</title></head>
<body>
<form method="POST" action="test3.asp">
<p><select size="1" name="GenericAccounts">
<%=genericAccount%>
</select></p>
</form>
</body>
</html>

Aug 28 '06 #2
Thanks Michael. That did the trick.

Michael Kujawa wrote:
genericAccount = "<option value= & '"sName"' & >"

I would think should be

genericAccount = genericAccount & "<option value='" & sName & "'>" & sName &
"</option>"

<mc************@gmail.comwrote in message
news:11**********************@74g2000cwt.googlegro ups.com...
I hope this is the right group. I am very new to ASP so this is
probably a stupid question. I have some vbscript that query's AD and
populates a recordset. I know the recorset contains the information I
want by doing a Response.write. I am having problems dynamically
creating a drop down list from the data in the recordset. The drop down
is created but it is empty. Any help would be greatly appreciated. A
sample of the code:

<%
'On Error Resume Next
Set objRootDSE = GetObject("LDAP://RootDSE")
strDNSDomain = objRootDSE.Get("defaultNamingContext")
strOU = "OU=Generic Accounts,"
' Use ADO to search Active Directory.
Set objCommand = CreateObject("ADODB.Command")
Set objConnection = CreateObject("ADODB.Connection")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
objCommand.ActiveConnection = objConnection
strBase = "<LDAP://" & strOU &" " & strDNSDomain &">"
strFilter = "(&(objectCategory=person)(objectClass=user))"
strQuery = strBase & ";" & strFilter & ";cn;subtree"
objCommand.CommandText = strQuery
objCommand.Properties("Page Size") = 100
objCommand.Properties("Timeout") = 30
objCommand.Properties("Cache Results") = False
Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst
Do Until objRecordSet.EOF
sName = objRecordSet.Fields("cn").Value
'Response.Write(sName)
genericAccount = "<option value= & '"sName"' & >"

objRecordSet.MoveNext
Loop
%>
<html><head><title>Dynamic Drop-Down Menu Example</title></head>
<body>
<form method="POST" action="test3.asp">
<p><select size="1" name="GenericAccounts">
<%=genericAccount%>
</select></p>
</form>
</body>
</html>
Aug 28 '06 #3
mc************@gmail.com wrote:
I hope this is the right group. I am very new to ASP so this is
probably a stupid question. I have some vbscript that query's AD and
populates a recordset. I know the recorset contains the information I
want by doing a Response.write. I am having problems dynamically
creating a drop down list from the data in the recordset. The drop
down is created but it is empty. Any help would be greatly
appreciated. A sample of the code:

<%
'On Error Resume Next
Set objRootDSE = GetObject("LDAP://RootDSE")
strDNSDomain = objRootDSE.Get("defaultNamingContext")
strOU = "OU=Generic Accounts,"
' Use ADO to search Active Directory.
Set objCommand = CreateObject("ADODB.Command")
Set objConnection = CreateObject("ADODB.Connection")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
objCommand.ActiveConnection = objConnection
strBase = "<LDAP://" & strOU &" " & strDNSDomain &">"
strFilter = "(&(objectCategory=person)(objectClass=user))"
strQuery = strBase & ";" & strFilter & ";cn;subtree"
objCommand.CommandText = strQuery
objCommand.Properties("Page Size") = 100
objCommand.Properties("Timeout") = 30
objCommand.Properties("Cache Results") = False
Set objRecordSet = objCommand.Execute
This line is not needed - upon opening, the recordset is already
pointing at the first record unless EOF is true.:
objRecordSet.MoveFirst
Do Until objRecordSet.EOF
sName = objRecordSet.Fields("cn").Value
'Response.Write(sName)
Here is the problem:
genericAccount = "<option value= & '"sName"' & >"
Two problems:
1. You are overwriting genericAccount with each pass through the loop.
I' m sure that's not what you intended.
2. You've put the quotes in the wrong places - this line should generate
an error. I notice the first "On Error" line is commented out, so it's
puzzling you aren't getting an error message. When you view the page's
source in the browser, what do you see?
The line should be:
genericAccount = genericAccount & "<option value='" & sName & "'>"
Anyways, this is an inefficient way to accomplish this task. Here is
what I would do:

Set objRecordSet = objCommand.Execute
dim arData, i
If Not objRecordSet.EOF then arData = objRecordSet.GetRows(,,"cn")
objRecordSet.close : set objRecordSet= nothing
if isArray(arData) then
for i = 0 to ubound(arData,2)
genericAccount = genericAccount & "<option value='" & _
arData(0,i) & "'>"
next
end if

--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
Aug 28 '06 #4

mc************@gmail.com wote:
I hope this is the right group. I am very new to ASP so this is
probably a stupid question.
There is no such thing as a stupid question, just people acting stupid.
I have some vbscript that query's AD and
populates a recordset. I know the recorset contains the information I
want by doing a Response.write. I am having problems dynamically
creating a drop down list from the data in the recordset. The drop down
is created but it is empty. Any help would be greatly appreciated. A
sample of the code:
<snip>
objRecordSet.MoveFirst
Do Until objRecordSet.EOF
sName = objRecordSet.Fields("cn").Value
'Response.Write(sName)
genericAccount = "<option value= & '"sName"' & >"

objRecordSet.MoveNext
Loop
'Response.Write(sName)
genericAccount = "<option value= & '"sName"' & >"

objRecordSet.MoveNext
Loop
%>
<html><head><title>Dynamic Drop-Down Menu Example</title></head>
<body>
<form method="POST" action="test3.asp">
<p><select size="1" name="GenericAccounts">
<%=genericAccount%>
</select></p>
</form>
</body>
</html>
You have your loop in a strange place. You can create the value as a
string, and then place it in your HTML, or you can generate it in the
HTML. But, you should not be regenerating the same HTML over and over
again. Eg:

<% 'run query and open recordset %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN"
"http://www.w3.org/TR/REC-html40/strict.dtd">
<html lang="en">
<head>
<title>Dynamic Drop-Down Menu Example</title>
</head>
<body>
<form method="POST" action="test3.asp">
<label for="genericaccounts">Accounts</label>
<select name="genericaccounts" id="genericaccounts">
<% while not objRecordset.EOF
sName = objRecordSet.Fields("cn").Value
%>
<option value="<%=sName%>" <% if genericaccounts = sname
then%>selected="selected"<%end if%>><%=sName%></option>
<% objRecordset.Movenext
wend
objRecordset.Close
set objRecordset = nothing
'close connection to db if not needed again on page
%>
</select>
</form>
</body>
</html>

OR:

<%
while not objrecordset.EOF
genericaccounts = genericaccounts "<option value=" & chr(034) & sname &
chr(034) & "</option>&vbcrlf"
objrecordset.Movenext
'close recordset and close connection if not needed again
%>
<select name="genericaccounts">
<%=genericaccounts%>
</select>
</form>

OR even better would be to use the GetString method described here:
<http://www.4guysfromrolla.com/webtech/102600-1.shtml>

Do you see? You were overwriting the HTML over and over again. It is
also nice to show a value selected if the user has selected it. I
would _strongly_ suggest closing elements, it makes it easier to debug.
Although the closing tag for the option element is not required, it
might make your life easier.

--
Adrienne Boswell at work
Administrator nextBlock.com
http://atlas.nextblock.com/files/
Please respond to the group so others can share

Aug 28 '06 #5
Adrienne Boswell wrote:
>
You have your loop in a strange place. You can create the value as a
string, and then place it in your HTML, or you can generate it in the
HTML. But, you should not be regenerating the same HTML over and over
again. Eg:
I, on the other hand, think it's easier for maintenance if server-side
code is separated from html as much as possible, so I firmly agree with
his choice to run his loop before the <htmlelement, set his html to a
variable and response.write the variable later on inside the <html>
element. However, this is just a personal preference.
--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
Aug 28 '06 #6
Bob Barrows [MVP] wrote:
Anyways, this is an inefficient way to accomplish this task.
Here is what I would do:

Set objRecordSet = objCommand.Execute
dim arData, i
If Not objRecordSet.EOF then arData = objRecordSet.GetRows(,,"cn")
objRecordSet.close : set objRecordSet= nothing
if isArray(arData) then
for i = 0 to ubound(arData,2)
genericAccount = genericAccount & "<option value='" & _
arData(0,i) & "'>"
next
end if
And if your data has an apostrophe in it? I would opt for something more
like this:

genericAccount = genericAccount & "<option value=""" & _
Server.HTMLEncode(arData(0,i)) & """>" & _
Server.HTMLEncode(arData(0,i)) & "</option>"

I always use double quotes and Server.HTMLEncode() to write attributes
values from data sources outside my control. To be more precise, I would
also use HTMLEncode once per data item, would optionally set the selected
attribute, and would do the whole thing in JScript.

--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms.
Aug 28 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Kingdom | last post by:
I'm using this script to dynamicaly populate 2 dropdowns and dispaly the results. Choose a component type from the first drop down, lets say 'car' and the second box will list all the car...
5
by: C White | last post by:
I'm trying to write an asp script that will create a series of drop lists based on a table like: canada ontario toronto street name link canada ontario toronto road...
1
by: ayende | last post by:
Okay, I'm pretty sure that I'm doing everything right here, but something is very wrong in the result. I've a page that has a drop down list (with auto-post-back = true) and a place holder. ...
1
by: Jeff Gardner | last post by:
Greetings: I have a table with 3 pieces of data that I would like to use to dynamically populate 3 drop downs using javascript. The fields are state, orgname, office. If it's not already...
0
by: cindy | last post by:
I have a dynamic datagrid. I have custom classes for the controls public class CreateEditItemTemplateDDL : ITemplate { DataTable dtBind; string strddlName; string strSelectedID; string...
2
by: Jim Gregg | last post by:
Hello all, I am faced with some logic that I am unsure how to handle. Imagine that I am running a WMI query and I am outputting the data into a dynamically created ASP table control. Here is my...
4
by: phcmi | last post by:
I have a PropertyGrid question. My task is to replace a legacy dialog box presentation with a modern one. The dialog itself allows the user to set configuration settings in our application, so...
9
by: Tarscher | last post by:
hi all, I have this seemingly simple problem. I have lost a lot of time on it though. When a user selects a value from a dropdownlist (static control) a dynamic control is generated. I have...
4
by: audreyality | last post by:
I am new to javascript and appreciate any guidance on this issue, so thank you in advance for your advice! Situation: I am working with a form that will send information to a database. I need the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.