Hello,
I have a code that queries Active Directory and put logins and names into
the ArrayList. Then I need to bind this ArrayList to the DropdDownList,
making names as DataTextField and logins as DataValueFields.
I have no problem doing it, if I have only logins or only names, since
ArrayList always has one dimension. But I need them both. So the code looks
like this:
Sub Getallusers(ByVal selddl As DropDownList)
Try
Dim sAdsPath As String = "LDAP://seart01/dc=acdtraining,dc=com"
Dim de As New DirectoryEntry(sAdsPath, "Domain\user",
"password")
Dim ds1 As New DirectorySearcher(de)
ds1.Filter = "(objectCategory=person)"
ds1.Filter = "(objectClass=user)"
ds1.Filter = "(employeeType=ALT)"
'Dim colServers(100, 100) As String
Dim colServers As ArrayList
colServers = New ArrayList
Dim result As SearchResult
For Each result In ds1.FindAll()
colServers.Add(New String()
{result.Properties("displayName")(0),
result.Properties("samAccountName")(0)})
Next result
'colServers.Sort()
selddl.DataSource = colServers
??????????????????????????????????
selddl.DataBind()
de.Dispose()
Catch ex As Exception
Dim s As String = ex.Message
End Try
End Sub
The ArrayList is filling up OK, now each value contains two values - Name
(0) and Login(1). But how to extract them separately and make one a text
field and another - value field? Tried everything, but couldn't fugure out.
It's definitely possible, since each value has it's own index (0 or 1), but
I don't know how.
Alternatively, how would I use just an Array instead?
I would appreciate your help very much.
Thank you,
--
Peter 7 1989
Here's a reference example that uses a similar technique:
Sub PopulateDropDownList(ByVal ddl As DropDownList)
Dim al As New ArrayList()
For i As Integer = 0 To 10
al.Add(New LoginClass("Login: " & i.ToString(), "Name: " &
i.ToString()))
Next
ddl.DataSource = al
ddl.DataTextField = "Login"
ddl.DataValueField = "Name"
ddl.DataBind()
End Sub
Class LoginClass
Public Readonly Property Name() As String
Get
Return _name
End Get
End Property
Public Readonly Property Login() As String
Get
Return _login
End Get
End Property
Private _login As String
Private _name As String
Public Sub New(ByVal login As String, ByVal name As String)
_login = login
_name = name
End Sub
End Class
Hope I've helped.
-Alan
Thank you very much, Alan. I've heard that creating a class would be a best
solution, but wasn't sure how to do this.
Peter
"Alan Samet" <al*******@gmail.com> wrote in message
news:11**********************@g44g2000cwa.googlegr oups.com... Here's a reference example that uses a similar technique:
Sub PopulateDropDownList(ByVal ddl As DropDownList) Dim al As New ArrayList() For i As Integer = 0 To 10 al.Add(New LoginClass("Login: " & i.ToString(), "Name: " & i.ToString())) Next ddl.DataSource = al ddl.DataTextField = "Login" ddl.DataValueField = "Name" ddl.DataBind() End Sub
Class LoginClass Public Readonly Property Name() As String Get Return _name End Get End Property
Public Readonly Property Login() As String Get Return _login End Get End Property
Private _login As String Private _name As String Public Sub New(ByVal login As String, ByVal name As String) _login = login _name = name End Sub End Class
Hope I've helped.
-Alan
Peter,
You add an array of two strings to your arraylist, therefore probably what
you want is to get the first two arraylist items.
\\\
dim mystring1 as string = directcast(arraylist(0),string())(0)
and
dim mystring2 as string = directcast(arraylist(0),string())(1)
///
Roughly typed not tested.
I hope this helps,
Cor
Peter,
A much easier solution is building a datatable and use that (has as well not
so much overhead by extra classes, if needed sorting etc because all code is
build in standard in the system.net namespace for that).
\\\
dim dt as datatable
dt.columns.add("person")
dt.columns.add("user")
for each in................
dt.rows.add(dt.newrow)
dt.rows(0) = first item
dt.rows(1) = second itme
next
drpdown.datasource = dt
drpdown.datatextfield = "person"
drpdown.datavalufield = "user"
drpdown.databind
////
I hope this helps,
Cor
"Peter Afonin" <pv*@speakeasy.net> schreef in bericht
news:eC****************@TK2MSFTNGP11.phx.gbl... Hello,
I have a code that queries Active Directory and put logins and names into the ArrayList. Then I need to bind this ArrayList to the DropdDownList, making names as DataTextField and logins as DataValueFields.
I have no problem doing it, if I have only logins or only names, since ArrayList always has one dimension. But I need them both. So the code looks like this:
Sub Getallusers(ByVal selddl As DropDownList) Try Dim sAdsPath As String = "LDAP://seart01/dc=acdtraining,dc=com" Dim de As New DirectoryEntry(sAdsPath, "Domain\user", "password") Dim ds1 As New DirectorySearcher(de) ds1.Filter = "(objectCategory=person)" ds1.Filter = "(objectClass=user)" ds1.Filter = "(employeeType=ALT)" 'Dim colServers(100, 100) As String Dim colServers As ArrayList colServers = New ArrayList Dim result As SearchResult
For Each result In ds1.FindAll() colServers.Add(New String() {result.Properties("displayName")(0), result.Properties("samAccountName")(0)}) Next result 'colServers.Sort() selddl.DataSource = colServers
??????????????????????????????????
selddl.DataBind() de.Dispose() Catch ex As Exception Dim s As String = ex.Message End Try End Sub
The ArrayList is filling up OK, now each value contains two values - Name (0) and Login(1). But how to extract them separately and make one a text field and another - value field? Tried everything, but couldn't fugure out. It's definitely possible, since each value has it's own index (0 or 1), but I don't know how.
Alternatively, how would I use just an Array instead?
I would appreciate your help very much.
Thank you,
-- Peter
Ha -- funny I didn't think of it earlier. You may also use the
sortedlist or hashtable classes to accomplish key-value databinding as
well.
example:
Sub PopulateDropDownList(ByVal ddl As DropDownList)
Dim sl As New SortedList() 'Hashtable()
For i As Integer = 0 To 10
sl.Add("Login: " & i.ToString(), "Name: " & i.ToString())
Next
ddl.DataSource = sl
ddl.DataTextField = "Key"
ddl.DataValueField = "Value"
ddl.DataBind()
End Sub
Thank you very much, Cor. I'll try it your way. I've tried before something
similar, but messed something up.
Peter
"Cor Ligthert [MVP]" <no************@planet.nl> wrote in message
news:es*************@TK2MSFTNGP12.phx.gbl... Peter,
A much easier solution is building a datatable and use that (has as well
not so much overhead by extra classes, if needed sorting etc because all code
is build in standard in the system.net namespace for that).
\\\ dim dt as datatable dt.columns.add("person") dt.columns.add("user") for each in................ dt.rows.add(dt.newrow) dt.rows(0) = first item dt.rows(1) = second itme next drpdown.datasource = dt drpdown.datatextfield = "person" drpdown.datavalufield = "user" drpdown.databind ////
I hope this helps,
Cor
"Peter Afonin" <pv*@speakeasy.net> schreef in bericht news:eC****************@TK2MSFTNGP11.phx.gbl... Hello,
I have a code that queries Active Directory and put logins and names
into the ArrayList. Then I need to bind this ArrayList to the DropdDownList, making names as DataTextField and logins as DataValueFields.
I have no problem doing it, if I have only logins or only names, since ArrayList always has one dimension. But I need them both. So the code looks like this:
Sub Getallusers(ByVal selddl As DropDownList) Try Dim sAdsPath As String =
"LDAP://seart01/dc=acdtraining,dc=com" Dim de As New DirectoryEntry(sAdsPath, "Domain\user", "password") Dim ds1 As New DirectorySearcher(de) ds1.Filter = "(objectCategory=person)" ds1.Filter = "(objectClass=user)" ds1.Filter = "(employeeType=ALT)" 'Dim colServers(100, 100) As String Dim colServers As ArrayList colServers = New ArrayList Dim result As SearchResult
For Each result In ds1.FindAll() colServers.Add(New String() {result.Properties("displayName")(0), result.Properties("samAccountName")(0)}) Next result 'colServers.Sort() selddl.DataSource = colServers
??????????????????????????????????
selddl.DataBind() de.Dispose() Catch ex As Exception Dim s As String = ex.Message End Try End Sub
The ArrayList is filling up OK, now each value contains two values -
Name (0) and Login(1). But how to extract them separately and make one a text field and another - value field? Tried everything, but couldn't fugure out. It's definitely possible, since each value has it's own index (0 or 1), but I don't know how.
Alternatively, how would I use just an Array instead?
I would appreciate your help very much.
Thank you,
-- Peter
Cor, with a few modifications your solution worked great for me, thank you
very much.
Dim result As SearchResult
Dim dt As DataTable = New DataTable
dt.Columns.Add("Name")
dt.Columns.Add("Login")
Dim n As Integer = 0
For Each result In ds1.FindAll()
dt.Rows.Add(dt.NewRow)
dt.Rows(n)("Name") = result.Properties("displayName")(0)
dt.Rows(n)("Login") = result.Properties("samAccountName")(0)
n = n + 1
Next result
Dim dv As DataView = dt.DefaultView
dv.Sort = "Name"
selddl.DataSource = dv
selddl.DataTextField = "Name"
selddl.DataValueField = "Login"
selddl.DataBind()
Peter
"Cor Ligthert [MVP]" <no************@planet.nl> wrote in message
news:es*************@TK2MSFTNGP12.phx.gbl... Peter,
A much easier solution is building a datatable and use that (has as well
not so much overhead by extra classes, if needed sorting etc because all code
is build in standard in the system.net namespace for that).
\\\ dim dt as datatable dt.columns.add("person") dt.columns.add("user") for each in................ dt.rows.add(dt.newrow) dt.rows(0) = first item dt.rows(1) = second itme next drpdown.datasource = dt drpdown.datatextfield = "person" drpdown.datavalufield = "user" drpdown.databind ////
I hope this helps,
Cor
"Peter Afonin" <pv*@speakeasy.net> schreef in bericht news:eC****************@TK2MSFTNGP11.phx.gbl... Hello,
I have a code that queries Active Directory and put logins and names
into the ArrayList. Then I need to bind this ArrayList to the DropdDownList, making names as DataTextField and logins as DataValueFields.
I have no problem doing it, if I have only logins or only names, since ArrayList always has one dimension. But I need them both. So the code looks like this:
Sub Getallusers(ByVal selddl As DropDownList) Try Dim sAdsPath As String =
"LDAP://seart01/dc=acdtraining,dc=com" Dim de As New DirectoryEntry(sAdsPath, "Domain\user", "password") Dim ds1 As New DirectorySearcher(de) ds1.Filter = "(objectCategory=person)" ds1.Filter = "(objectClass=user)" ds1.Filter = "(employeeType=ALT)" 'Dim colServers(100, 100) As String Dim colServers As ArrayList colServers = New ArrayList Dim result As SearchResult
For Each result In ds1.FindAll() colServers.Add(New String() {result.Properties("displayName")(0), result.Properties("samAccountName")(0)}) Next result 'colServers.Sort() selddl.DataSource = colServers
??????????????????????????????????
selddl.DataBind() de.Dispose() Catch ex As Exception Dim s As String = ex.Message End Try End Sub
The ArrayList is filling up OK, now each value contains two values -
Name (0) and Login(1). But how to extract them separately and make one a text field and another - value field? Tried everything, but couldn't fugure out. It's definitely possible, since each value has it's own index (0 or 1), but I don't know how.
Alternatively, how would I use just an Array instead?
I would appreciate your help very much.
Thank you,
-- Peter
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Harry |
last post by:
I want to bind three elements of an seven element arraylist to a data grid.
I cannot find an example of complex binding specific fields of an array list
to a datagrid.
Any examples would be...
|
by: Peter Afonin |
last post by:
Hello,
I have a code that queries Active Directory and put logins and names into
the ArrayList. Then I need to bind this ArrayList to the DropdDownList,
making names as DataTextField and logins...
|
by: Morten Hauge |
last post by:
Hi!
I have a problem, I'm not sure if this is the proper way to do it, but I
have the following scenario:
I want to list all categories, and all products in that category whenever I
select a...
|
by: Bob Lehmann |
last post by:
Hi,
I'm trying to bind an ArrayList to a DataList.
I get the error
DataBinder.Eval: 'System.String' does not contain a property with the name
Name.
I don't know what property of ArrayList...
|
by: john wright |
last post by:
I have a dictionary oject I created and I want to bind a listbox to it. I
am including the code for the dictionary object.
Here is the error I am getting:
"System.Exception: Complex...
| |
by: serge calderara |
last post by:
Dear all,
Does anyone know how to bind a System.Collection.ArraysList object to a
Dataset ?
Thanks for your reply
Regards
Serge
|
by: sck10 |
last post by:
Hello,
I am trying to bind an arraylist to a FormView DropDownList control in the
PreRender state. The error that I get is the following:
Databinding methods such as Eval(), XPath(), and...
|
by: vineetbatta |
last post by:
I have Custom Data class which stores data about single customer and then i
store that customer objects in arraylist as shown below.
Customer custdata = null; // Custom Data class for 1 customer...
|
by: weird0 |
last post by:
Purpose: The objective is to update or add a new row in datagridview
using an arraylist
I have an arraylist inside of a class and i added an object to the
arraylist on the button click event....
|
by: pbd22 |
last post by:
Hi.
I am returning to an old bit of code in our program and need to figure
out how to sort
my columns on bind. I am sorting on Date (mostly) and some other
values.
Problem is, the code is an...
|
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,...
| |
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: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |