title: catching SelectedIndexChanged of a dropdown list inside a repeater
body: <p>I am trying to catch the SelectedIndexChanged of a DropDownList inside a Repeater. I have searched the internet but could not find a specific answer any help would be great. This is my code. </p>
  
  <h2>page.aspx</h2>
  
  <pre><code>&lt;asp:Repeater id="CategoryMyC" OnItemCommand="SomeEvent_ItemCommand" runat="server"&gt;
      &lt;HeaderTemplate&gt;
          &lt;table&gt;&lt;tr&gt;
      &lt;/HeaderTemplate&gt;
      &lt;ItemTemplate&gt;
          &lt;td&gt;
              &lt;table width="100%"&gt;
                  &lt;tr&gt;
                      &lt;th&gt;Edit Carousel Item&lt;/th&gt;
                  &lt;/tr&gt;
                  &lt;tr&gt;
                      &lt;td&gt;Choose a product:&lt;/td&gt;
                  &lt;/tr&gt;
                  &lt;tr&gt;
                      &lt;td&gt;
                          &lt;asp:DropDownList ID="ddlMcProducts" 
                                            DataTextField="Name"
                                            onselectedindexchanged="MyListIndexChanged"
                                            AutoPostBack="true"  
                                            DataSource='&lt;%# ProductsManager.GetMerchantProductRepeater(Convert.ToInt32(Eval("MID"))) %&gt;'  
                                            runat="server"&gt;
                          &lt;/asp:DropDownList&gt;
                      &lt;/td&gt;
                  &lt;/tr&gt;
              &lt;/table&gt;                          
          &lt;/td&gt;                
      &lt;/ItemTemplate&gt;
      &lt;FooterTemplate&gt;
          &lt;/tr&gt;
       &lt;/table&gt;
       &lt;/FooterTemplate&gt;
   &lt;/asp:Repeater&gt;
  </code></pre>
  
  <h2>page.aspx.cs</h2>
  
  <p>In the Page_Load:</p>
  
  <pre><code>List&lt;CarouselProducts&gt; CP = CarouselProductsManager.GetCarouselItems(Convert.ToInt32(Session["Mid"]));
  CategoryMyC.DataSource = CP;
  CategoryMyC.ItemDataBound += new  RepeaterItemEventHandler(RepeaterItemDataBound);
  CategoryMyC.DataBind();
  </code></pre>
  
  <p>Other events:</p>
  
  <pre><code>protected void ddlMcProducts_SelectedIndexChanged(object sender, EventArgs e)
  {
      DropDownList d = (DropDownList)sender;
      // Use d here
  
      System.Windows.Forms.MessageBox.Show("I am changing");
  }
  
  protected virtual void PageInit(object sender, EventArgs e)
  {
      //get all the Carousel item of the merchant
      List&lt;CarouselProducts&gt; CP = CarouselProductsManager.GetCarouselItems(Convert.ToInt32(Session["Mid"]));
      //MerchantCategoryMyCarousel.DataSource = CP;
      //MerchantCategoryMyCarousel.DataBind();
  
      MerchantCategoryMyCarousel.DataSource = CP;
      MerchantCategoryMyCarousel.ItemDataBound += new RepeaterItemEventHandler(RepeaterItemDataBound);
      MerchantCategoryMyCarousel.DataBind();
  }
  
  protected virtual void RepeaterItemDataBound(object sender, RepeaterItemEventArgs e)
  {
      DropDownList theDropDown = sender as DropDownList;
      if (e.Item.ItemType == ListItemType.EditItem)
      {
          DropDownList MyList = (DropDownList)e.Item.FindControl("ddlMcProducts");
          if (MyList == null)
          {
              System.Windows.Forms.MessageBox.Show("Did not find the controle");
          }
          else
              MyList.SelectedIndexChanged += new EventHandler(MyListIndexChanged);
      }
  }
  
  protected virtual void MyListIndexChanged(object sender, EventArgs e)
  {
      System.Windows.Forms.MessageBox.Show("I am changing");
  }
  
  protected void SomeEvent_ItemCommand(object sender, RepeaterCommandEventArgs e)
  {
      if (e.CommandSource.GetType() == typeof(DropDownList))
      {
          DropDownList ddlSomething = (DropDownList)e.Item.FindControl("ddlSomething");
          System.Windows.Forms.MessageBox.Show("I am changing");
          //Now you can access your list that fired the event
          //SomeStaticClass.Update(ddlSomething.SelectedIndex);
      }
  }
  </code></pre>
  
  <p>I need to catch the SelectedIndexChanged of the populated DropDownList for each one generated.</p>