I am dynamically creating multiple dropdownlists (with unique ids each) and binding them to a panel. I have also written the SelectedIndexChanged code for them which gets fired everytime a dropdown is changed. My problem is as there is only one SelectedIndexChanged event, I need to get the id of the dropdownlist which is changed. How can I get that?
Here is my code for binding the dropdownlists to the panel:
foreach (Document offer in parent.Children)
{
Panel pnlCat = new Panel();
pnlCat.ID = offer.Id.ToString();
pnlCat.CssClass = "ngx";
DropDownList ddl = new DropDownList();
ddl.ID = offer.Id + "_cat";
ddl.DataTextField = "catName";
ddl.DataValueField = "catId";
ddl.CssClass = "ddlStyle";
ddl.DataSource = category;
ddl.DataBind();
ddl.AutoPostBack = true;
ddl.SelectedIndexChanged += new EventHandler(ddl_SelectedIndexChanged);
pnlCat.Controls.Add(ddl);
}
and here is the SelectedIndexChanged code:
void ddl_SelectedIndexChanged(object sender, EventArgs e)
{
string id = this.ClientID;
}
In the id i get "_page". How can i get the dropdownlist ID?
The
sender
refers to the object that invoked the event that fired the event handler.