【发布时间】:2016-11-24 22:04:06
【问题描述】:
我在这里为我的项目寻求一点帮助。 在我的代码中,我有两个下拉列表。第一个列表在页面加载时填充来自 LDAP 查询的结果。因此,该下拉菜单效果很好,并为用户提供了 AD 中的活动用户列表。
现在这是我的头疼... 我的项目中有一个 formview 控件。我在 edititem 模板中放置了一个额外的下拉列表。我想要做的是将第一个下拉列表的内容复制到第二个下拉列表中。我遇到的问题是,当我尝试为第二个控件编写代码时,我不断收到第二个控件尚未声明的错误,这对我来说实际上很有意义,因为表单实际上并不存在页面,直到有人在 formview 绑定到的 gridview 控件中选择一个索引。
我在想,为了做到这一点,我需要在 formview 的 edititem 事件上使用 .findcontrol 运算符。但是,当我尝试这样做时,我仍然收到有关未声明控件 ID 的错误。我会把到目前为止我尝试过的东西粘贴在这里..
'' 这是我在后面的代码中填充第一个下拉列表的地方
Dim dirEntry As DirectoryEntry = New DirectoryEntry("LDAP:MyIPaddress", "MyDomain/Username", "MyPassword", AuthenticationTypes.FastBind)
Dim searcher As DirectorySearcher = New DirectorySearcher(dirEntry)
'' Filter the search so that it only pulls up Active user accounts. The search filter "!userAccountControl:1.2.840.113556.1.4.803:=2" removes
'' disabled users from the list. For a list of all attributes defined by Active Directory, see https://msdn.microsoft.com/en-us/library/ms675090(v=vs.85).aspx
searcher.Filter = "(&(objectClass=User)(objectCategory=person)(!userAccountControl:1.2.840.113556.1.4.803:=2))"
'' Loop through the search results and add each user as string types to list controls
Dim userNames As New List(Of String)
For Each resEnt As SearchResult In searcher.FindAll()
Dim userName As String = resEnt.Properties("name")(0).ToString()
userNames.Add(userName)
Next
userNames.Sort()
For Each userName In userNames
userList.Items.Add(userName)
Next
'' 到目前为止,这是我在尝试找到第二个控件时所做的...
Protected Sub FormView1_DataBound(sender As Object, e As System.EventArgs) Handles FormView1.DataBound
If FormView1.CurrentMode = FormViewMode.Edit Then
DropDownList(userListEdit = FormView1.FindControl("userListEdit"))
End If
End Sub
'' 当我尝试编写最后一行来查找控件时,我收到一条错误消息,指出未声明控件。我试图在许多不同的在线论坛中找到解决方案。但似乎没有什么能准确地给我我需要的东西。有谁知道我如何找到这个控件并在后面的代码中复制内容?提前致谢!
【问题讨论】:
标签: asp.net vb.net drop-down-menu formview