Results 1 to 2 of 2

Thread: Dynamic drop down list passing parameters

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2005
    Posts
    1,170

    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
            }

  2. #2
    Frenzied Member
    Join Date
    Mar 2004
    Location
    Orlando, FL
    Posts
    1,618

    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
  •  



Click Here to Expand Forum to Full Width