Get the current index in an ASP.Net 2.0 Repeater control

.net, asp.net, drop-down-menu, repeater

Solution

Try:

<asp:DropDownList runat="server" id="myDDL" OnSelectedIndexChanged="myDDL_Changed" />

//fired when the DDL selected index changes
void myDDL_Changed(object sender, EventArgs e)
{
    //sender is the ddl
    DropDownList theDropDown = sender as DropDownList;
    int repeaterItemIndex = ((RepeaterItem)theDropDown.NamingContainer).ItemIndex;
}

Problem

Maybe this is something very easy to do it but so far it's taking me all day to have something working. I have a repeater filled with a table. Each row in the repeater has a set of controls. The most important of them is a drop down list with AutoPostback = true. This ddl has to postback when the user changes the selected index so I can hide/show controls within the ddl. The problem is that when the user changes the selected index in the ddl, and the control postback, in the server side, I can't get the index of the row that contains the ddl that made postback. Hope it's clear enough, and that someone can help me out here. Thanks! EDIT: Maybe this is something that wasn't clear enough: when I place a control with ID="ddlSomething" inside an ItemTemplate in a repeater, and I have 5 rows in the data source, I will have 5 rows in the repeater with 5 ddl with the same id (on the server side, in the client side will be something like "ctl01$ddlSomething", "ctl02$ddlSomething". My problem is that when the ddl postback, I don't know which of all these 5 (for example) ddl is the one that made the postback, because just looking at Request.Form variables I can see that the control "ddlSomething" made it.

Original source