Active Directory - Dropdown vs. Grid Oddity

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • programmher
    New Member
    • Jan 2014
    • 19

    Active Directory - Dropdown vs. Grid Oddity

    I have a page that another developer wrote that displays an Active Directory group list in a gridview. If you click the select link, the members of the selected group display in another grid.

    I have another page that uses the same datasources and displays the Active Directory groups in a dropdown box. If you select a particular group, the members of that group display in a listbox.

    The strange thing is - for some reason there are some groups that will not display any members in the listbox. There is no error message. Just nothing displayed in the listbox.

    Why is this happening? The datasources are the same just being displayed differently.

    Any ideas how I resolve this?
  • zmbd
    Recognized Expert Moderator Expert
    • Mar 2012
    • 5501

    #2
    Can't help you without the code.

    When you post the script, please place it between [CODE] [/CODE] tags by clicking on the [CODE/] button in the toolbar.

    Comment

    • programmher
      New Member
      • Jan 2014
      • 19

      #3
      I ran debugger and no issues were detected.

      Here is the active directory code and the code that populates the dropdown boxes.

      I find it very odd that using the same object source yields two different results, though. The results from the dropdown box are also very inconsistent. Either all of the members from the active directory groups should display or none of the members from the active directory groups display- not just what seems to be random.

      Code:
      using System;
      using System.Collections.Generic;
      using System.Configuration;
      using System.DirectoryServices;
      using System.DirectoryServices.AccountManagement;
      using System.Linq;
      using System.Web;
      using Library.Media;
      
      
      public class GenreSelection
      {
          private string _display, _distinguished, _name, _sam;
      
          public string authorname { get { return _display; } }
          public string DistinguishedName { get { return _distinguished; } }
          public string Name { get { return _name; } }
          public string SAMAccountName { get { return _sam; } }
       
          public GroupSelection()
       {
         
       }
      
          public static List<Genres> GetAuthorGroupList()
          {
              List<GenreSelection> groups = new List<GenreSelection>();
              DirectorySearcher ds = new DirectorySearcher(new DirectoryEntry("LDAP://dc=dadecountylib,dc=net"));
              ds.Filter = "(&(objectClass=group)(proxyAddresses=*))";
              SearchResultCollection src = ds.FindAll();
      
              foreach (SearchResult sr in src)
              {
                  if (!sr.Properties.Contains("msexchhidefromaddresslists") || (sr.Properties["msexchhidefromaddresslists"][0].ToString() != "True"))
                  {
                      GroupSelection gs = new GroupSelection();
                      if (sr.Properties.Contains("name")) gs._name = sr.Properties["name"][0].ToString();
                      if (sr.Properties.Contains("authorname")) gs._display = sr.Properties["authorname"][0].ToString();
                      if (sr.Properties.Contains("samaccountname")) gs._sam = sr.Properties["samaccountname"][0].ToString();
                      if (sr.Properties.Contains("distinguishedname")) gs._distinguished = sr.Properties["distinguishedname"][0].ToString();
                      groups.Add(gs);
                  }
      
              }
              return groups;
          }
      
          public static List<Authors> GetAuthorsForGenre(string GroupName)
          {
              List<Authors> users = new List<Authors>();
              string domain = ConfigurationManager.AppSettings["DOMAIN"];
      
              if (GroupName != null)
              {
                  PrincipalContext pc = new PrincipalContext(ContextType.Domain);
                  GroupPrincipal gp = new GroupPrincipal(pc);
                  PrincipalSearcher ps = new PrincipalSearcher(gp);
                  ps.QueryFilter.SamAccountName = GroupName;
                  GroupPrincipal result = (GroupPrincipal)ps.FindOne();
                  if (result != null)
                  {
                      foreach (Principal pp in result.Members)
                      {
                          TrackingUser tu = null;
                          try
                          {
                              tu = new Authors(String.Format(@"{0}\{1}", domain, pp.SamAccountName));
                          }
                          catch (Exception ex) { }
                          if (tu == null)
                          {
                              try
                              {
                                  tu = Authors.CreateUserFromActiveDirectory((UserPrincipal)pp);
                              }
                              catch (Exception ex) { }
                          }
                          if (tu != null) users.Add(tu);
                      }
      
                  }
              }
      
              return users;
          }
      }
      
       
      
       
      
      {
               
              lbAuthorsList.DataBind();
          }
      
            protected void genreList_SelectedIndexChanged(object sender, EventArgs e)
          {
             
      lbAuthorsList.DataBind();  
          }
      Code:
       <asp:DropDownList runat="server" ID="lbGenreList" 
                       style="float:left;" DataSourceID="odsGenres" 
                       DataTextField="Authorame" DataValueField="AuthorName" 
                       onselectedindexchanged="genreList_SelectedIndexChanged" 
                       AutoPostBack="True" AppendDataBoundItems="true" 
              onprerender="btnSortData_Click">
         </asp:DropDownList>  
             <asp:ListBox runat="server" ID="lbAuthorNameList" DataTextField="AuthorName" 
                  DataValueField="AuthorID" DataSourceID="Authors" SelectionMode="Multiple"  AppendDataBoundItems="true" /> 
      
       
      
      <asp:ObjectDataSource ID="AuthorsList" runat="server" 
                  SelectMethod="GetAuthorList" TypeName="Library.Media.GetAuthors">  
             
      
      <asp:ObjectDataSource ID="odsGenres" runat="server" SelectMethod="GetAuthorsForGenres" TypeName="GenreSelection">
                  <SelectParameters>
                      <asp:ControlParameter Name="GenreName" Type="String" ControlID="lbGenreList" ConvertEmptyStringToNull="true" />
                  </SelectParameters>
              </asp:ObjectDataSource>
      Last edited by Frinavale; Jan 24 '14, 06:51 PM.

      Comment

      Working...