title: Remove items from DropDownList
body: <p>I have two DropDownLists one for the type of a soldier and one for the number of soldiers the player i allowed to buy. I populate ddlSoldiers with a LinqDataSource in the aspx page like this:</p>
  
  <pre><code>&lt;asp:DropDownList ID="ddlSoldiers" runat="server" 
                      DataSourceID="LinqDataSource2" DataTextField="type" 
                      DataValueField="troopid" AutoPostBack="True"&gt;
                  &lt;/asp:DropDownList&gt;
                  &lt;asp:LinqDataSource ID="LinqDataSource2" runat="server" 
                      ContextTypeName="BrowserSpill.LinqClass1DataContext" EntityTypeName="" 
                      Select="new (type, troopid)" TableName="Troops"&gt;
                  &lt;/asp:LinqDataSource&gt;
  </code></pre>
  
  <p>The other list ddlSoldierNumber is populated in the pageload like this:</p>
  
  <pre><code>protected void Page_Load(object sender, EventArgs e)
      {
  
          if (Session["userRole"] == null || Session["userRole"].Equals("admin"))
          {
              Response.Redirect("Login.aspx");
          }
  
          int userid = Convert.ToInt32(Session["userid"]);
  
          if(string.IsNullOrEmpty(ddlSoldiers.SelectedValue))
          {
              var varTroopType = dc.Troops.Single(t =&gt; t.troopid == 1).type;
              string troopType = Convert.ToString(varTroopType);
  
              var varBuildingId = dc.Buildings.Single(b =&gt; b.soldierType == troopType).buildingid;
              int buildingId = Convert.ToInt32(varBuildingId);
  
              var varNumberOfBuildings =
              dc.Towns.Single(t =&gt; (t.buildingid == buildingId) &amp;&amp; (t.userid == userid)).number;
  
              int numberOfBuildings = Convert.ToInt32(varNumberOfBuildings);
  
              for (int i = 1; i &lt; numberOfBuildings + 1; i++)
              {
                  ddlSoldierNumber.Items.Add(i.ToString());
              }
          }
          else
          {
  
              ddlSoldierNumber.Items.Clear();
  
              string troopType = ddlSoldiers.SelectedItem.Text;
  
              var varBuildingId = dc.Buildings.Single(b =&gt; b.soldierType == troopType).buildingid;
              int buildingId = Convert.ToInt32(varBuildingId);
  
              var varNumberOfBuildings =
                  dc.Towns.Single(t =&gt; (t.buildingid == buildingId) &amp;&amp; (t.userid == userid)).number;
  
              int numberOfBuildings = Convert.ToInt32(varNumberOfBuildings);
  
  
              for(int i = 1; i &lt; numberOfBuildings+1; i++)
              {
                  ddlSoldierNumber.Items.Add(i.ToString());
              }
  
          }
      }
  </code></pre>
  
  <p>But when i want to get the values from ddlSoldierNumber i only get the first value in that list. I try to get the number with the click of a button like this:</p>
  
  <pre><code>protected void btnBuySoldier_Click(object sender, EventArgs e)
      {
          string numbertobuy = ddlSoldierNumber.SelectedItem.Value;
          lblAntall.Text = numbertobuy;
      }
  </code></pre>
  
  <p>I have tried to put the line:</p>
  
  <pre><code>ddlSoldierNumber.Items.Clear();
  </code></pre>
  
  <p>other places but without any luck. Does anyone know how i can clear the number list after I press the button and before the ddlSoldierNumber get repopulated?</p>