title: .NET web form drop down list resets on postback
body: <p>I've searched through a heap of similar questions and done a bit of googling but I cannot find the answer to my problem...</p>
  
  <p>I would like to have a drop down list that is populated by categories in a database...upon selecting a category and hitting submit, a gridview is populated with all the items in that category. </p>
  
  <p>Now, everything works, except whenever I select anything in the category drop down box, it resets straight away to the first selection. So I'm unable to submit any value other than the first to the gridview.  I am using autopostback on this item. I have tried to use appenddatabounditems too but that just populated the list with more and more of the same entries...</p>
  
  <p>I would love if anyone could tell me how I can just get the dropdownlist to hold its position after postback?</p>
  
  <pre><code>Selected Category:
      &lt;asp:DropDownList ID="ddlCategory" runat="server" AutoPostBack="True" ViewStateMode="Enabled"&gt;
      &lt;/asp:DropDownList&gt;
      &lt;asp:Button ID="buttonCategorySubmit" runat="server" OnClick="buttonCategorySubmit_Click" Text="Submit" /&gt;
      &lt;br /&gt;
  
  &lt;/div&gt;
      &lt;asp:GridView ID="CategoryGridView" runat="server"&gt;
      &lt;/asp:GridView&gt;
      &lt;br /&gt;
  
   protected void Page_Load(object sender, EventArgs e)
      {
          PopulateCategorySelection();
      }
  
      public void PopulateCategorySelection()
      {
          SqlConnection conn = new SqlConnection(ConfigurationManager.AppSettings["ConnString"]);
          SqlCommand cmd = new SqlCommand("AllCategories", conn);
          cmd.CommandType = CommandType.StoredProcedure;
          conn.Open();
          SqlDataReader ddlValues = cmd.ExecuteReader();
          ddlCategory.DataSource = ddlValues;
          ddlCategory.DataValueField = "CategoryID";
          ddlCategory.DataTextField = "Title";
          ddlCategory.DataBind();
  
          conn.Close();
  
  
      }
  
      protected void buttonCategorySubmit_Click(object sender, EventArgs e)
      {
          PopulateCategoryTable();
      }
  
      public void PopulateCategoryTable()
      {
          SqlConnection conn = new SqlConnection(ConfigurationManager.AppSettings["Connstring"]);
          SqlCommand cmd = new SqlCommand("SelectCategory", conn);
          cmd.CommandType = CommandType.StoredProcedure;
  
          cmd.Parameters.AddWithValue("@Selected", ddlCategory.SelectedItem.Value);
  
          conn.Open();
  
          SqlDataAdapter adapter = new SqlDataAdapter();
          DataSet ds = new DataSet();
          adapter = new SqlDataAdapter(cmd);
          adapter.Fill(ds);
          conn.Close();
          CategoryGridView.DataSource = ds.Tables[0];
          CategoryGridView.DataBind();
  
          conn.Close();
      }
  </code></pre>