Dynamic drop down list passing parameters
I have a dynamic created drop down list - and I set the event of it to be like this:
ddlAnswer.ID = "ddlistAnswer" + QuestionID;
ddlAnswer.SelectedIndexChanged += new EventHandler(ddlAnswer_SelectedIndexChanged);
Please note that drop down list is dynamic, and in selectedIndexChanged, I would like to pass the "QuestionID" to that selectedindexchanged to work on my logic. Is there a way to pass it to that method as command argument or something?
Code:
protected void ddlAnswer_SelectedIndexChanged(object sender, EventArgs e)
{
//wanting that question id here
}
Re: Dynamic drop down list passing parameters
Probably lot's of ways to do it, e.g.:
Dim MyID as int32= Convert.ToInt32(Replace(DirectCast(sender, DropDownList).ID,"ddlAnswer",""))
I think that will work, basically strip your ID back out of the Drop Down Name and convert it to an Int assuming your ID is an Int.
(Edit: Actually that is VB Code, you are using C# aren't you?)
Int32 MyID = Convert.ToInt32(Strings.Replace(((DropDownList)sender).ID, "ddlAnswer", ""));