Click here to Skip to main content
15,941,071 members
Please Sign up or sign in to vote.
4.00/5 (2 votes)
See more:
I found this code and have been attempting to Bind it to a listview control with no success (The idea is to display the members of a group defined in a gridview in another Panel). If I setup an ObjectDatasource and use a DefaultValue it displays the members of that group (although the formating is out of whack).


Code behind
public SortedList FillMembersList(string groupName)
    {
        
        SortedList groupMembers = new SortedList();
        string sam = "";
        string fname = "";
        string lname = "";
        string active = "";
        DirectoryEntry de = new DirectoryEntry("LDAP://DC=CSUMAIN,DC=csu,DC=edu,DC=au");
        DirectorySearcher ds = new DirectorySearcher(de, "(objectClass=person)");
        ds.Filter = "(memberOf=CN=" + groupName + ",OU=Distribution Groups (DLs),OU=Managed,DC=CSUMAIN,DC=csu,DC=edu,DC=au)";
        
        ds.PropertiesToLoad.Add("givenname");
        ds.PropertiesToLoad.Add("samaccountname");
        ds.PropertiesToLoad.Add("sn");
        ds.PropertiesToLoad.Add("useraccountcontrol");
        foreach (SearchResult sr in ds.FindAll())
        {
            try
            {
                sam = sr.Properties["samaccountname"][0].ToString();
                fname = sr.Properties["givenname"][0].ToString();
                lname = sr.Properties["sn"][0].ToString();
                active = sr.Properties["useraccountcontrol"][0].ToString();
            }
            catch
            {
            }
            // don't grab disabled users
            if (active.ToString() != "514")
            {
                groupMembers.Add(sam.ToString(), (fname.ToString() + " " + lname.ToString()));
            }
        }
        
        return groupMembers;
        
    }



Code in front
XML
<asp:Panel Style="display: none; left: 630px; z-index: 100; position: absolute;
                        top: 52px" ID="PanelEditGroups" runat="server" Height="267px"
                        Width="258px" BorderWidth="2px"
                        BorderStyle="Inset" ScrollBars="Vertical" EnableViewState="True"
                        Visible="True">

                    <asp:ListView ID="ADGroupListView" runat="server">
                    <LayoutTemplate>
                        <table cellpadding="2" width="640px" border="1" runat="server" id="table">
                            <tr id="Tr1" runat="server">
                            <th id="Th1" runat="server">test</th>
                            </tr>
                            <tr runat="server" id="itemPlaceholder" />
                            </table>
                        </LayoutTemplate>
                        <itemtemplate><%# Eval("Key")%></itemtemplate>

                    </asp:ListView>

                    </asp:Panel>
Posted

1 solution

 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900