您好我需要一些帮助来理解如何数据绑定到从vb.net函数生成的arraylist。我似乎遇到两个错误,具体取决于数组列表的位置()(函数内部或外部)。寻找有关如何解决问题的建议,使用函数中的值填充下拉列表。感谢
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title></title>
</head>
<body>
<br />
<asp:DropDownList ID="dd1" runat="server" AutoPostBack="True"></asp:DropDownList>
<br />
</body>
</html>
Imports System
Imports System.DirectoryServices
Imports System.DirectoryServices.ActiveDirectory
Partial Class _Default
Inherits System.Web.UI.Page
Public Function EnumerateDomains() As ArrayList
Dim DomainList As New ArrayList()
' DomainList As New ArrayList
Dim currentForest As Forest = Forest.GetCurrentForest()
Dim currentDomains As DomainCollection = currentForest.Domains
'Dim CurrentDomain As String
For Each currentDomain As Domain In currentDomains
DomainList.Add("currentDomain.Name")
Next
DomainList.TrimToSize()
DomainList.Sort()
Return DomainList
End Function
Protected Sub Selection_Changed(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles Me.Load
If Not Page.IsPostBack Then
'DropDownList1.Items.Clear()
DropDownList1.DataSource=DomainList
DropDownList1.DataBind()
'DropDownList1.SelectedIndex=0
End If
End Sub
End Class
答案 0 :(得分:0)
我使用下面的函数收集了一个列表,并使用databind填充下拉列表。我的下一步是自动填充下拉列表中的sec,自动填充具有该特定域的用户。
Public Function EnumerateDomains() As ArrayList
Dim alDomains As New ArrayList()
Dim currentForrest As Forest = Forest.GetCurrentForest()
Dim myDomains As DomainCollection = currentForrest.Domains
For Each objDomain As Domain In myDomains
alDomains.Add(objDomain.Name)
Next
Return alDomains
End Function