title: DropDownList lose index after PostBack
body: <p>I have a dropdown which I fill with data from a SQL server.</p>
  
  <p>I fill the dropdown dynamically in the <code>Page_Init()</code> Event.
  Depending on the Value, a ListItem is selected.</p>
  
  <p>Now the problem is, that when I select another Item in the dropdown, that after the postback the selection is reset to the first item in the dropdownlist.</p>
  
  <p>This here is a basic version of my code which does not work:</p>
  
  <pre><code>        ArrayList AD_Group_Members = ActiveDirectory.GetMemberOfGroup("AD-Group");
          ArrayList ListMachines = SQLQuery.Read("Database", "SELECT idVM, RandomString, Computername, Owner, FROM VM ORDER BY Computername");
  
          for (int i = 0; i &lt; ListMachines.Count; i++)
          {
              String RandomString = ((Hashtable)ListMachines[i])["RandomString"].ToString();
              String Owner = ((Hashtable)ListMachines[i])["Owner"].ToString();
              DropDownList DropDownList_Owner = new DropDownList();
              DropDownList_Owner.ID = "DropDownList_Owner_" + RandomString;
              DropDownList_Owner.Width = Unit.Percentage(95);
              DropDownList_Owner.AutoPostBack = true;
              DropDownList_Owner.EnableViewState = true;
              DropDownList_Owner.SelectedIndexChanged += DropDownList_Owner_SelectedIndexChanged;
              Div_Test.Controls.Add(DropDownList_Owner);
              for (int y = 0; y &lt; AD_Group_Members.Count; y++)
              {
                  ListItem ListItem = new ListItem();
                  ListItem.Value = Owner;
                  ListItem.Text = ((Hashtable)AD_Group_Members[y])["GivenName"].ToString() + " " + ((Hashtable)AD_Group_Members[y])["Surname"].ToString();
                  if (((Hashtable)AD_Group_Members[y])["Username"].ToString().Equals(Owner))
                  {
                      ListItem.Selected = true;
                  }
                  DropDownList_Owner.Items.Add(ListItem);
              }
          }
  </code></pre>
  
  <p>Where is the issue in my code, that it doesn't work but the example.
  Thank in Advance</p>