如何获得动态创建DropDownLists的顺序 [英] How to get the order of dynamically created DropDownLists

查看:97
本文介绍了如何获得动态创建DropDownLists的顺序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创造了一些下拉使用JavaScript,ASP.NET名单。

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.

如果很难理解我的意思请参见<一个href=\"http://stackoverflow.com/questions/10101262/how-to-implement-a-list-of-dropboxes-in-c-sharp\">How实现在C#保管箱列表。

If it's hard to understand what I mean pls see " How to implement a list of dropboxes in C# ".

现在我想实现的背后code和要定义下拉列表的顺序,但我不知道哪一个是我的第一个下拉列表等。

And now I'd like to implement the code behind and want to define the order of the drop down lists, but I don't know which one is my first drop down list, etc.

我们假定所有的&LT; ASP:DropDownList的&GT; 包含列表元素如下:方法1,方法2,method3和method4。如果用户选择的元素,在codebehind的方法来实现。

We assume that all <asp:DropDownList> contain the following for list elements: method1, method2, method3 and method4. If a user selects an element, a method in the codebehind is implemented.

例如:
dropboxlist1:选择列表项的方法2,结果
dropboxlist2:选择列表项的方法1,结果
dropboxlist3:选择列表项method3,

Example: dropboxlist1: select list item method2,
dropboxlist2: select list item method1,
dropboxlist3: select list item method3,

string txt= "";
if (dropboxlistID.Text == "method1"){
  txt = method1Imp();
} else if (dropboxlistID.Text == "method2") {
  txt = method2Imp();
} else if (dropboxlistID.Text == "method3") {
  txt = method3Imp();
} else {
}

但此时此刻我没有哪个下拉列表是先和方法应该在我的第一个字符串进行任何想法。

But at this moment I don't have any idea which drop down lists came first and which method should be performed on my string first.

推荐答案

尝试入队的每个方法进入队列作为一个代表,那么排水(调用每一个代表)队列一旦你从一个单独的线程准备好了。这将确保执行顺序的用户选择的顺序相匹配。

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.

对不起,我没有initally包括code。这里有一个基本的例子,让你开始:

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);
}

...
Sometime Later 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/简单任务queue.html

这篇关于如何获得动态创建DropDownLists的顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆