title: DropDownList OnSelectedIndexChanged - Cancel the selected value
body: <p>I have a panel, which contains a ListView with an itemTemplate which contains for each element a dropdowlist, two textboxes and one delete's button.</p>
  
  <p>Each dropdownlist of each Listview elements contains the same datas, a list of values from a datasource, but the selected values are differents in differents rows. Certains values can be the same, it depends of a constraint.</p>
  
  <p>This constraint, for some elements from my dropdownlist, is that i can have the same value on two rows.</p>
  
  <p>I bound my dropdownlist with OnSelectedIndexChanged event and autoPostback to True in the design : </p>
  
  <pre><code>&lt;asp:DropDownList ID="ddlLinkToDestinationParent" CssClass="ddl-link-to ddl-link-to-child" runat="server"  AutoPostBack="True" OnSelectedIndexChanged="ddlNewConsumptionLinkToDestinationParent_OnSelectedIndexChanged" data-headcount='&lt;%# Eval("HeadCount") %&gt;' /&gt;
  </code></pre>
  
  <p>I pass in my event (server side).</p>
  
  <pre><code>var ddl = sender as DropDownList;
  
          if (IsDestinationSelected(ddl))
          {
              // Display error message
              // cancel the selection of my dropdownlist or select another value...
  
          }
  </code></pre>
  
  <p>The method IsDestinationSelected permit to know if my dropdownlist with a this value and with the constraint is found. If true, i want to cancel my selected item of my dropdownlist</p>
  
  <p>What can i write after the error message ?</p>
  
  <p>I try some solutions, but nothing interessant... (320 is juste for test, but is a list item) : </p>
  
  <pre><code>ddl.SelectedIndex = ddl.Items.IndexOf(ddl.Items.FindByValue("320"));
  </code></pre>
  
  <p>This is my list item : </p>
  
  <pre><code>&lt;select name="ctl00$Main$lvSetConsumptionsSite$ctrl1$ddlLinkToDestinationParent" onchange="javascript:setTimeout('__doPostBack(\'ctl00$Main$lvSetConsumptionsSite$ctrl1$ddlLinkToDestinationParent\',\'\')', 0)" id="ctl00_Main_lvSetConsumptionsSite_ctrl1_ddlLinkToDestinationParent" class="ddl-link-to ddl-link-to-child" data-headcount="0"&gt;
      &lt;option value=""&gt;--- Type de consom° ---&lt;/option&gt;
      &lt;option value="870"&gt;petit dejeuner 1 siege&lt;/option&gt;
      &lt;option value="877"&gt;petit dejeuner 2 (siege)&lt;/option&gt;
      &lt;option value="133"&gt;dejeuner 1 siege&lt;/option&gt;
      &lt;option value="26"&gt;dejeuner 2 (siege)&lt;/option&gt;
      &lt;option value="237"&gt;dejeuner 3 (siege)&lt;/option&gt;
      &lt;option value="238"&gt;dejeuner 4 (siege)&lt;/option&gt;
      &lt;option value="239"&gt;dejeuner 5 (siege)&lt;/option&gt;
      &lt;option value="241"&gt;dejeuner 6 (siege)&lt;/option&gt;
      &lt;option value="288"&gt;dejeuner 7 (siege)&lt;/option&gt;
      &lt;option value="852"&gt;pique nique (gouter 1 siege)&lt;/option&gt;
      &lt;option value="507"&gt;diner 1 (siege)&lt;/option&gt;
      &lt;option value="883"&gt;test 20/09 (diner - siege)&lt;/option&gt;
      &lt;option value="136"&gt;Goûter 2 (siege)&lt;/option&gt;
      &lt;option value="134"&gt;Resident (pas dans CM)&lt;/option&gt;
      &lt;option value="24"&gt;pertes (diner - siege)&lt;/option&gt;
      &lt;option value="25"&gt;cessions (pas dans CM)&lt;/option&gt;
      &lt;option value="201"&gt;Taxes et Frais divers (pas dans CM)&lt;/option&gt;
      &lt;option value="227"&gt;Emballages (consignes et déconsignes)&lt;/option&gt;
      &lt;option value="135"&gt;Diners de luxe (pas dans CM)&lt;/option&gt;
      &lt;option selected="selected" value="320"&gt;ajustement de stock&lt;/option&gt;
      &lt;option value="334"&gt;autre&lt;/option&gt;
      &lt;option value="745"&gt;HAPPY&lt;/option&gt;
      &lt;option value="876"&gt;consommation&lt;/option&gt;
      &lt;option value="802"&gt;test AB Cons 3105 01&lt;/option&gt;
      &lt;option value="869"&gt;panier repas (pas dans CM)&lt;/option&gt;
      &lt;option value="915"&gt;1 dest. siege&lt;/option&gt;
      &lt;option value="953"&gt;collation de 11h&lt;/option&gt;
  
  &lt;/select&gt;
  </code></pre>
  
  <p>But when i try to change my value or my item, i call another time my event, but with the value selected, also infinite loop...</p>
  
  <p>Do you have an idea ?</p>
  
  <p>Thanks for your answer !</p>