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(ByV al selddl As DropDownList)
Try
Dim sAdsPath As String = "LDAP://seart01/dc=acdtraining, dc=com"
Dim de As New DirectoryEntry( sAdsPath, "Domain\use r",
"password")
Dim ds1 As New DirectorySearch er(de)
ds1.Filter = "(objectCategor y=person)"
ds1.Filter = "(objectClass=u ser)"
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.Propert ies("displayNam e")(0),
result.Properti es("samAccountN ame")(0)})
Next result
'colServers.Sor t()
selddl.DataSour ce = 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 1997
Here's a reference example that uses a similar technique:
Sub PopulateDropDow nList(ByVal ddl As DropDownList)
Dim al As New ArrayList()
For i As Integer = 0 To 10
al.Add(New LoginClass("Log in: " & i.ToString(), "Name: " &
i.ToString()))
Next
ddl.DataSource = al
ddl.DataTextFie ld = "Login"
ddl.DataValueFi eld = "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*******@gmai l.com> wrote in message
news:11******** **************@ g44g2000cwa.goo glegroups.com.. . Here's a reference example that uses a similar technique:
Sub PopulateDropDow nList(ByVal ddl As DropDownList) Dim al As New ArrayList() For i As Integer = 0 To 10 al.Add(New LoginClass("Log in: " & i.ToString(), "Name: " & i.ToString())) Next ddl.DataSource = al ddl.DataTextFie ld = "Login" ddl.DataValueFi eld = "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(arra ylist(0),string ())(0)
and
dim mystring2 as string = directcast(arra ylist(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.datasou rce = dt
drpdown.datatex tfield = "person"
drpdown.dataval ufield = "user"
drpdown.databin d
////
I hope this helps,
Cor
"Peter Afonin" <pv*@speakeasy. net> schreef in bericht
news:eC******** ********@TK2MSF TNGP11.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(ByV al selddl As DropDownList) Try Dim sAdsPath As String = "LDAP://seart01/dc=acdtraining, dc=com" Dim de As New DirectoryEntry( sAdsPath, "Domain\use r", "password") Dim ds1 As New DirectorySearch er(de) ds1.Filter = "(objectCategor y=person)" ds1.Filter = "(objectClass=u ser)" 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.Propert ies("displayNam e")(0), result.Properti es("samAccountN ame")(0)}) Next result 'colServers.Sor t() selddl.DataSour ce = 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 PopulateDropDow nList(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.DataTextFie ld = "Key"
ddl.DataValueFi eld = "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******** *****@TK2MSFTNG P12.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.datasou rce = dt drpdown.datatex tfield = "person" drpdown.dataval ufield = "user" drpdown.databin d ////
I hope this helps,
Cor
"Peter Afonin" <pv*@speakeasy. net> schreef in bericht news:eC******** ********@TK2MSF TNGP11.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(ByV al selddl As DropDownList) Try Dim sAdsPath As String =
"LDAP://seart01/dc=acdtraining, dc=com" Dim de As New DirectoryEntry( sAdsPath, "Domain\use r", "password") Dim ds1 As New DirectorySearch er(de) ds1.Filter = "(objectCategor y=person)" ds1.Filter = "(objectClass=u ser)" 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.Propert ies("displayNam e")(0), result.Properti es("samAccountN ame")(0)}) Next result 'colServers.Sor t() selddl.DataSour ce = 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)("Nam e") = result.Properti es("displayName ")(0)
dt.Rows(n)("Log in") = result.Properti es("samAccountN ame")(0)
n = n + 1
Next result
Dim dv As DataView = dt.DefaultView
dv.Sort = "Name"
selddl.DataSour ce = dv
selddl.DataText Field = "Name"
selddl.DataValu eField = "Login"
selddl.DataBind ()
Peter
"Cor Ligthert [MVP]" <no************ @planet.nl> wrote in message
news:es******** *****@TK2MSFTNG P12.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.datasou rce = dt drpdown.datatex tfield = "person" drpdown.dataval ufield = "user" drpdown.databin d ////
I hope this helps,
Cor
"Peter Afonin" <pv*@speakeasy. net> schreef in bericht news:eC******** ********@TK2MSF TNGP11.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(ByV al selddl As DropDownList) Try Dim sAdsPath As String =
"LDAP://seart01/dc=acdtraining, dc=com" Dim de As New DirectoryEntry( sAdsPath, "Domain\use r", "password") Dim ds1 As New DirectorySearch er(de) ds1.Filter = "(objectCategor y=person)" ds1.Filter = "(objectClass=u ser)" 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.Propert ies("displayNam e")(0), result.Properti es("samAccountN ame")(0)}) Next result 'colServers.Sor t() selddl.DataSour ce = 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 appreciated.
m_Stat = new Stat(str1,str2,str3,str4,str5);
m_arrlstStats.Add(m_Stat);
|
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 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...
|
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 topcategory in a menu.
Example:
- Music
|
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 I should be using instead of "Name"
in default.aspx.
|
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 DataBinding accepts as a data source either an
IList or an IListSource
at System.Windows.Forms.ListControl.set_DataSource(Object value)
| |
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 Bind() can only be used in
the context of a databound control. Any help with this would be
appreciated.
--
Thanks in advance,
|
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 data.
ArrayList ar = new ArrayList(); // To store more than one customer
object.
for (int x = 0; x < 30; x++)
{
custdata = new 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. Then, after clearing the
datagridview1, i re-assigned the arraylist to the datasource property.
But it does not work, since the application crashes....
|
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 ArrayList that seems to do some
tricky stuff with a chache object and I am unable to get any sort of
sorting happening.
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
| |
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it. ...
|
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...
| |