|
-
Mar 6th, 2013, 01:39 PM
#1
Thread Starter
Frenzied Member
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
}
-
Mar 6th, 2013, 02:40 PM
#2
Frenzied Member
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", ""));
Sean
Some days when I think about the next 30 years or so of my life I am going to spend writing code, I happily contemplate stepping off a curb in front of a fast moving bus.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|