使用ASP删除下拉列表中的重复条目

时间:2015-10-28 12:08:43

标签: asp-classic active-directory

我有一段代码会显示一个服务区列表,然后,当您选择一个服务区时,它会在第二个下拉框中返回一个部门列表。我有以下代码:

 <%@ Language="VBScript"%>
 <% response.Buffer = TRUE
 'Defines the variables and objects
 dim ADUser, RecordList, intOne, intTwo, intThree, companies, service_area, department, arrComp
 'Assigns the objComp and objDept variables to Scripting Dictionary objects
 %>
 <!--#include file="includes/functions.asp"-->
 <!--#include file="includes/display.asp"-->
 <!--#include file="includes/results.asp"-->
 <!--#include file="includes/timer.asp"-->
 <h1>Organisational Structure</h1>
 <div class="commandspace">
 <p class="infotext">The org structure can be viewed with or without staff, indented or left justified.</p>
 </div>
 <% 
 ADUser = "LDAP://RBCTHDC1/OU=Staff,OU=Users,DC=example,DC=internal"
 ' Make AD connection and run query
 Set objCon = Server.CreateObject("ADODB.Connection")
 objCon.provider ="ADsDSOObject"
 objCon.Properties("User ID") = "DOMAIN\username"
 objCon.Properties("Password") = "Password"
 objCon.Properties("Encrypt Password") = TRUE
 objCon.open "Active Directory Provider"
 Set objCom = CreateObject("ADODB.Command")
 Set objCom.ActiveConnection = objCon 
 objCom.CommandText ="select company FROM '"& ADUser &"' where company ='*'" 
 Set objRS = objCom.Execute 'Creates an object and runs the LDAP query
 companies = objRS.GetRows()
 set arrComp = Server.CreateObject("Scripting.Dictionary")
 for intOne = 0 to UBound(companies,2)
      if not arrComp.exists(companies(0, intOne)) then
      arrComp.add companies(0, intOne), companies(0, intOne)
      end if
 next 
 response.write "<form action='index.asp?View=Structure' method='POST'>"
 response.write "<select id='service_area' name='service_area' onChange='showTeams(this.value)'>"
 response.write "<option>Please Select</option>"
 for intTwo = 0 to arrComp.Count
      response.write "<option value='"& Server.URLEncode(arrComp.Item(intTwo)) &"'>" & arrComp.Item(intTwo) & "</option>"  & VBCrlF
 next
 response.write "</select>"   & VBCrlF
 response.write "<span class='structure-spacing'></span>"  & VBCrlF
 response.write "<select id='department' name='department'></select>"  & VBCrlF
 response.write "<span class='structure-spacing'></span>"  & VBCrlF
 response.write "<input type='submit' name='submit' id='submit'>"  & VBCrlF
 response.write "</form>"  & VBCrlF
 if request.form("submit")="Submit" then
      service_area = request.form("service_area")
      department = request.form("department")
      if service_area = "Please Select" then 

      response.write "<p>Service area cannot be left empty</p>"

      end if

      if IsEmpty(department) then 

      response.write "<p>Department cannot be left empty</p>"

      end if
        objCom.CommandText ="select company, department, title, cn FROM '"& ADUser &"' where department = '" & department & "' ORDER BY department" 
 else
      objCom.CommandText ="select company, department, title, cn FROM '"& ADUser &"' where company ='*' ORDER BY department" 
 end if
 Set objRS = objCom.Execute 'Creates an object and runs the LDAP query
 RecordList = objRS.GetRows()
 response.write "<table>"  & VBCrlF
 response.write "<thead>"  & VBCrlF
 response.write "<tr>"  & VBCrlF
 response.write "<th>Service Area</th>"  & VBCrlF
 response.write "<th>Department</th>"  & VBCrlF
 response.write "<th>Job Title</th>"  & VBCrlF
 response.write "<th>Name</th>"  & VBCrlF
 response.write "</tr>"  & VBCrlF
 response.write "</thead>"  & VBCrlF
 response.write "<tbody>"  & VBCrlF
 for intThree = 0 to UBound(RecordList,2)
      response.write "<tr>"  & VBCrlF
      response.write "<td>" & RecordList(3, intThree) & "</td>"  & VBCrlF
      response.write "<td>" & RecordList(2, intThree) & "</td>"  & VBCrlF
      response.write "<td>" & RecordList(1, intThree) & "</td>"  & VBCrlF
      response.write "<td>" & RecordList(0, intThree) & "</td>"  & VBCrlF
      response.write "</tr>"  & VBCrlF
 next
 response.write "</tbody>"  & VBCrlF
 response.write "</table>"  & VBCrlF
 objRS.Close
 objCon.Close
 Set objCon = Nothing
 Set objCom = Nothing
 %>     

我无法找到删除重复条目的方法。使用脚本字典,我得到一个空的下拉框。它没有返回服务区列表,也没有返回任何内容 - 只是一个空的选项值

0 个答案:

没有答案