2014-11-09 77 views
-2

嗨,我需要一些幫助,瞭解如何綁定到從vb.net函數生成的數組綁定。根據數組列表的位置()(函數內部或外部),我似乎遇到兩個錯誤。尋找關於如何解決問題的建議,使用函數中的值填充下拉列表。由於asp dropdownlist via databinding to 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

'DomainList.Add(「currentDomain.Name」)'不可能是正確的,每次迭代都會有同樣的結果。它可能是'DomainList.Add(currentDomain.Name)' – OneFineDay 2014-11-09 01:35:51

+0

嘗試使用或不使用speachmarks,加載頁面,但在採用該概念之後,列表不會出現 – Maverick 2014-11-09 11:46:46

+0

,您更改答案並接受您的答案。 – HaveNoDisplayName 2014-11-14 17:41:26

回答

0

我收集使用下面的功能列表,並使用數據綁定填充下降downlist。我的下一步是自動填充下拉列表中的秒自動填充具有該特定域的用戶。

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