title: Drop Down List SelectedIndexChanged event handler fires multiple times inside ListView control
body: <p>I have a list view control which I am binding using <code>DataTable</code>. In the <code>ItemDataBound</code> I am creating <code>DropDownList</code> and adding items programmatically and binding <code>SelectedIndexChanged</code> event to that drop down.</p>
  
  <p>In my case, suppose three rows are created in the ListView and there are three Drop Downs in the list view. When I change the drop down selection to first <code>DropDownList</code> then <code>SelectedIndexChanged</code> fires one time. Then I change the selection in second <code>DropDownList</code> then <code>SelectedIndexChanged</code> fires two times and then I change the selection in second <code>DropDownList</code> then <code>SelectedIndexChanged</code> fires three times.</p>
  
  <pre><code>protected void dlMain_ItemDataBound(object sender, System.Web.UI.WebControls.DataListItemEventArgs e)
  {
      if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
      {
          DataRowView currentRow = (DataRowView)e.Item.DataItem;
          Panel pnl = (Panel)e.Item.FindControl("pnlUser");
          if (pnl != null)
          {
              pnl.Controls.Add(new LiteralControl(currentRow.Row.ItemArray[1].ToString()));
          }
          Panel pnlDropDown = (Panel)e.Item.FindControl("pnlDropDown");
          if (pnlDropDown != null)
          {
              if (dtCustomers.Rows.Count &gt; 0)
              {
                  DataRow[] customers = dtCustomers.Select("KItemId = " + Convert.ToInt32(currentRow.Row.ItemArray[0]) + "");
                  if (customers.Length &gt; 0)
                  {
                      DropDownList customerDDL = new DropDownList();
                      ListItem baseItem = new ListItem("-- Select --", "0");
                      customerDDL.Items.Add(baseItem);
                      foreach (DataRow customerRow in customers)
                      {
                          ListItem newItem = new ListItem(customerRow["CustName"].ToString(), customerRow["CustId"].ToString());
                          customerDDL.Items.Add(newItem);
                      }
                      customerDDL.ID = "Customers" + Convert.ToString(currentRow.Row.ItemArray[0]);
                      customerDDL.AutoPostBack = true;
                      customerDDL.SelectedIndexChanged += customerDDL_SelectedIndexChanged;
                      pnlDropDown.Controls.Add(customerDDL);
                  }
              }
          }
      }
  }  
  </code></pre>
  
  <p>To check the behavior of event I wrote the single line of code in the <code>SelectedIndexChanged</code> event</p>
  
  <pre><code>void customerDDL_SelectedIndexChanged(object sender, EventArgs e)
  {
  
      DropDownList changedList = (DropDownList)sender;
  
  }
  </code></pre>
  
  <p>Here when I fist change the selected value of DropDown1 then I am getting the <code>ID</code> DropDown1 then I change the selected value of DropDown2  the event fires two times and in first time I am getting id of sender object DrowDown1 and then again control comes in the event and I get the sender object DropDown2.  </p>
  
  <p>What should I do to get the exact control's selected item in the <code>SelectedIndexChanged</code>?</p>