title: How to programmatically add a Drop down list in asp.net with specific pre-selected item
body: <p>I've worked out how to create a DropDownList using the following code:</p>
  
  <pre><code>&lt;select id="salesPersonDropList" runat="server"&gt;&lt;/select&gt;
  </code></pre>
  
  <p>In my .aspx page, then my code behind loops through database output running:</p>
  
  <pre><code>Dim newListItem As ListItem
  newListItem = New ListItem("Title", "Value")
  salesPersonDropList.Items.Add(newListItem )
  </code></pre>
  
  <p>What I can't figure out is how to programatically set which of the List Items created is the one to be pre-selected in the rendered DropDownList, ie, how to create what I'd write in HTML as:</p>
  
  <pre><code>&lt;select&gt;
       &lt;option value="1"&gt;1&lt;/option&gt;
       &lt;option selected value="2"&gt;2&lt;/option&gt;
  &lt;/select&gt;
  </code></pre>
  
  <p>Based on database output. As the code behind loops through the database output it should compare the output to a session variable and if they values match, the ListItem should be the item selected in the rendered DropDown.</p>