title: How can you set the selected item in an ASP.NET dropdown via the display text?
body: <p>I have an ASP.NET dropdown that I've filled via databinding. I have the text that matches the display text for the listitem I want to be selected. I obviously can't use SelectedText (getter only) and I don't know the index, so I can't use SelectedIndex. I currently am selecting the item by iterating through the entire list, as show below:</p>
  
  <p>ASP:</p>
  
  <pre><code>&lt;asp:DropDownList ID="ddItems" runat="server" /&gt; 
  </code></pre>
  
  <p>Code:</p>
  
  <pre><code>ddItems.DataSource = myItemCollection;
  ddItems.DataTextField = "Name";
  ddItems.DataValueField = "Id";
  
  foreach (ListItem item in ddItems.Items)
  {
      if (item.Text == textToSelect)
      {
          item.Selected = true;
      }
  }
  </code></pre>
  
  <p>Is there a way to do this without iterating through all the items? </p>