Skip to content Skip to sidebar Skip to footer

How To Get The Order Of Dynamically Created Dropdownlists

I've created some drop down lists using JavaScript, ASP.NET. A user can add as many drop down lists as he wants by clicking a '+' button and removing them by clicking a '-' button

Solution 1:

Try enqueueing each method into a queue as a delegate, then draining (invoking each delegate) the queue once you're ready from a single thread. This will ensure that the order of execution matches the order of user choices.

Sorry I didn't initally include code. Here's a basic example to get you started:

Queue<Func<string>> actions = new Queue<Func<string>>();
if(dropboxListID.Text=="m1")
{
 actions.Enqueue(method1Imp);
}
if(dropboxListID.Text="m2")
{
 action.Enqueue(method2Imp);
}

...SometimeLater when you're ready to process these
...
string txt ="";    
while(actions.Count>0)
{
 var method = actions.Dequeue();
 txt = method();
}

Here's a blog post that delves further into the concept of a work/task queue:

http://yacsharpblog.blogspot.com/2008/09/simple-task-queue.html

Solution 2:

IMO your drop down lists will be contained in a parent.

Let us say (acc to your link) your parent is DropDownPlaceholder.

<div id="DropDownPlaceholder">

Use linq to get all children of it. Cast them as drop down lists and then your can loop on them to find your matter.

Solution 3:

To get the order of dropdownlists:

  1. First set the IDs/ClientIDs of hard-coded dropdownlists in aspx page and count them (say 2 dropdownlists are present)
  2. While creating dropdownlists dynamically, append a count integer at the end of their IDs/ClientIDs like ddl3, ddl4 (start the count from 3)
  3. Then in your code, you can find the dropdownlist of selected element:

    if (ddl.ClientID.EndsWith("1")){
      // 1st ddl
    } elseif (ddl.ClientID.EndsWith("2")) {
      // 2nd ddl
    } elseif (ddl.ClientID.EndsWith("3")) {
      // 3rd ddl
    }
    ...
    

Post a Comment for "How To Get The Order Of Dynamically Created Dropdownlists"