title: Databinding selected items in html select from asp.net
body: <p>I am coding in asp.net and I have added the html select control as seen below. I need to also databind some of the values to be pre-selected, how do I do that?</p>
  
  <pre><code>&lt;select multiple="true" runat="server" id="SelectControlID" 
      datasource='&lt;%# GetItems(Convert.ToInt64(DataBinder.Eval(Container.DataItem, "ID"))) %&gt;' 
      datatextfield='LocationName' datavaluefield='LocationID'&gt;
  &lt;/select&gt;
  </code></pre>
  
  <p>Please note that I have to have runat="Server" as I need to retrieve the values in code behind. This means I cannot do something of the form below as that is not allowed with runat server.</p>
  
  <pre><code>&lt;asp:Repeater runat="server" DataSource='SOMETHING'&gt;
      &lt;ItemTemplate&gt;
          &lt;option &lt;%# DataBinder.Eval(Container.DataItem, "SelectedHTML") %&gt; 
                  value='&lt;%# DataBinder.Eval(Container.DataItem, "LocationID") %&gt;'&gt;
                  &lt;%# DataBinder.Eval(Container.DataItem, "LocationName") %&gt;
          &lt;/option&gt;
      &lt;/ItemTemplate&gt;
  &lt;/asp:Repeater&gt;
  </code></pre>
  
  <p>In the end my requirements is a dropdown that allows multi select of items and being able to databind pre-selected items and retrieve its values on server side. I tried doing this with a select html control as above and using <a href="http://www.erichynds.com/blog/jquery-ui-multiselect-widget" rel="nofollow" title="jquery multiselect widget">jquery multiselect widget</a>. Please help me get the rest of the way or suggest an easy alternative.</p>