Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old January 8th, 2010, 05:33 PM
Friend of Wrox
 
Join Date: Mar 2007
Location: West Palm Beach, Florida, USA.
Posts: 205
Thanks: 4
Thanked 0 Times in 0 Posts
Question Fill DropDownList with users from AD

Need to fill a drop down list with users from Active Directory. Have code in place but the "For Each..." does not render any data. Any ideas?

Code:
 
        Dim GroupSearcher As New DirectorySearcher
        Dim GroupSearchRoot As New DirectoryEntry
        GroupSearchRoot.Path = "LDAP://CN=users,DC=vecelliogroup,DC=com"
        GroupSearchRoot.Username = "mydomain\myuserid"
        GroupSearchRoot.Password = "mypassword"
        With GroupSearcher
            .SearchRoot = GroupSearchRoot
            .Filter = "(&(ObjectClass=Group)(CN=Domain Users))"
        End With
        Dim Members As Object = GroupSearcher.FindOne.GetDirectoryEntry.Invoke("Members", Nothing)
        For Each Member As Object In CType(Members, IEnumerable)
            Dim CurrentMember As New DirectoryEntry(Member)
            DropDownList5.Items.Insert(i, CurrentMember.Name.Remove(0, 3))
        Next
Reply With Quote
  #2 (permalink)  
Old January 12th, 2010, 08:05 AM
Friend of Wrox
 
Join Date: May 2006
Location: Northampton, United Kingdom.
Posts: 107
Thanks: 1
Thanked 8 Times in 7 Posts
Default

I've only used the Add command for programmatically adding to a drop down list so would the following work?

Change:
DropDownList5.Items.Insert(i, CurrentMember.Name.Remove(0, 3))
To:
DropDownList5.Items.Add(
New ListItem(i, CurrentMember.Name.ToString))

Can you explain what the CurrentMember.Name.Remove(0, 3) part of the code is intended to do as I've not encountered it before?
Reply With Quote
  #3 (permalink)  
Old January 12th, 2010, 09:35 AM
Friend of Wrox
 
Join Date: Mar 2007
Location: West Palm Beach, Florida, USA.
Posts: 205
Thanks: 4
Thanked 0 Times in 0 Posts
Question

I changed:

DropDownList5.Items.Insert(i, CurrentMember.Name.Remove(0, 3))
To:
DropDownList5.Items.Add(New ListItem(i, CurrentMember.Name.ToString))

Still does not work. Why I have no idea.

I changed my code to do following:

Code:
 
Dim Conn = CreateObject("ADODB.Connection")
Conn.Provider = "ADSDSOObject"
Dim SQLStmt As String = "select title, sAMAccountName, displayName from 'LDAP://10.xx.x.3/DC=Vecelliogroup,DC=COM' WHERE objectClass='User'"
Conn.Open("ADs Provider")
Dim rs = CreateObject("ADODB.Recordset")
rs = Conn.Execute(SQLStmt)
Try
Do While Not rs.EOF
DropDownList5.Items.Add(rs.Fields(0).ToString)
rs.MoveNext()
Loop
Catch ex As Exception
Message = ex.ToString
End Try
I do not get any values in my drop down list.

I have also created a linked server and this piece of code works in the query analyzer:

Code:
 
select * 
from openquery(ADSI_10_xx_x_3, ' 
select title, sAMAccountName, displayName 
from ''LDAP://DC=Vecelliogroup,DC=COM'' 
where objectClass = ''User''')
Now I wonder why my code behind does not work as I am doing same selection.
Reply With Quote
  #4 (permalink)  
Old January 12th, 2010, 11:03 AM
Friend of Wrox
 
Join Date: May 2006
Location: Northampton, United Kingdom.
Posts: 107
Thanks: 1
Thanked 8 Times in 7 Posts
Default

Is the problem in the section where you add to the drop down list or in the selection?

Try running the selection and instead of add the values to a dropdownlist add them to a text box to help you identify the section which causes the problem.

Let me know if the selection generates the correct values and I can then make more suggestions for the drop down list.
Reply With Quote
  #5 (permalink)  
Old January 12th, 2010, 01:25 PM
Friend of Wrox
 
Join Date: Mar 2007
Location: West Palm Beach, Florida, USA.
Posts: 205
Thanks: 4
Thanked 0 Times in 0 Posts
Question

Here is the code I now have:

Code:
 
Dim Conn = CreateObject("ADODB.Connection")
Dim RS = CreateObject("ADODB.Recordset")
Conn.Provider = "ADsDSOObject"
Dim strConn = "Active Directory Provider"
Conn.Open(strConn)
Dim strRS As String = "SELECT givenname 'LDAP://10.xx.x.3/DC=Vecelliogroup,DC=COM' WHERE objectClass = 'User'"
RS.Open(strRS, Conn, 1, 1)
Do While Not RS.EOF
Dim mystring As String
mystring = RS.fields(0).ToString
RS.MoveNext()
Loop
Value of String = System.__ComObject

I have taken this code from:

http://forums.aspfree.com/asp-develo...0.html?p=62691
Reply With Quote
  #6 (permalink)  
Old January 22nd, 2010, 05:24 AM
Registered User
 
Join Date: Dec 2009
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Fill Dropdownlist with users from AD

Hi,check this out.
Suppose in your application you are using a DropDownList in a Form and depending upon the item selection you are showing/hiding some views inside a Multiview and you want that the user must select one of the item from the DropDownList before submitting a Form.

So you can write code like the following to validate the DropDown :

<asp:DropDownList ID="ddlExpertLevel" runat="server" AutoPostBack="True" onselectedindexchanged="ddlExpertLevel_SelectedInd exChanged" >

<asp:ListItem Text="--Select--" Value="0" />

<asp:ListItem Text="Beginner" Value="1" />

<asp:ListItem Text="Intermediate" Value="2" />

<asp:ListItem Text="Advanced" Value="3" />

</asp:DropDownList>


<asp:RequiredFieldValidator ID="reqValQuestionType" runat="server" ErrorMessage="Level is required." Text="*" ControlToValidate="ddlExpertLevel" InitialValue="0">
</asp:RequiredFieldValidator>
This code will work fine but it has an issue. The issue is - If page validation returns false and after that you are trying to change the DropDown's index then it will not work for first time.
Because when you submit the form it will do Form validation. If Validation returns false [indicates not to submit the Form], then you can can't go to server side code. The problem lies here. Since you have used "SelectedstateChanged" event for the Dropdown, the code inside the event handler function will not execute after form validation[when validation will return false].

So How to handle this problem. The solution is very simple, you have to do the following things -

Make CausesValidation="false" for the DropDown.

Remove any validation group for that DropDown, i.e ValidationGroup="none"

Handle client side change event to avoid Blocking of Submit on DropDown item change, i.e onchange="Page_BlockSubmit = false;"

So the final code would look like :
<asp:DropDownList ID="ddlExpertLevel" runat="server" AutoPostBack="True"

CausesValidation="false" ValidationGroup="none" onchange="Page_BlockSubmit = false;"

onselectedindexchanged="ddlExpertLevel_SelectedInd exChanged" >

<asp:ListItem Text="--Select--" Value="0" />

<asp:ListItem Text="Beginner" Value="1" />

<asp:ListItem Text="Intermediate" Value="2" />

<asp:ListItem Text="Advanced" Value="3" />

</asp:DropDownList>


<asp:RequiredFieldValidator ID="reqValQuestionType" runat="server" ErrorMessage="Level is required." Text="*" ControlToValidate="ddlExpertLevel" InitialValue="0">
</asp:RequiredFieldValidator>

Thanks,
Suryakant
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Add existing AD user to AD group via ADSI? thiazi Classic ASP Basics 0 August 24th, 2007 09:27 PM
Pulling a Users Email from AD or Exchange Zeus_Man General .NET 0 September 14th, 2006 09:33 AM
How 2 fill a dropdownlist with a column in sql drpcken VB How-To 2 April 17th, 2004 09:34 PM



All times are GMT -4. The time now is 05:48 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.