下拉菜单充满了相同的列表项 [英] Dropdowns filled with same list item

查看:175
本文介绍了下拉菜单充满了相同的列表项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个GridView中,我的DropDownList有两个模板列。我必将他们与同一列表项的运行时

I have a Gridview in which i have two templatefields of dropdownlist. I bound them on runtime with same list item.

li = new listitem ("1","1");
dl1.items.add(li);
dl2.items.add(li);

li = new listitem ("2","2");
dl1.items.add(li);
dl2.items.add(li);

li = new listitem ("3","3");
dl1.items.add(li);
dl2.items.add(li);

dl1.selectedvalue = "2";
dl2.selectedvalue = "3";



以上执行,DL1&放后; DL2都告诉我3作为选择的值。为什么呢?

After executing above, dl1 & dl2 both show me "3" as selected value. Why?

我知道变通使用2个不同的时listItems而结合的,但我想知道为什么上面的情况?

I know the work around of using 2 different listitems while binding but i wanna know why the above happens?

推荐答案

该列表项类有,如果该项目被选中,这标志着一个属性选择。我没有检查的DDL SelectedValue属性,看看它做什么,但我的猜测是,ListItem.Selected属性被设置为true,因为你使用的是在这两个下拉列表同一个对象,它被标在这两个'选择'。

The ListItem class has a property "Selected" which marks if the item is selected. I haven't checked the DDL SelectedValue property to see what it does, but my guess is that the ListItem.Selected property is being set to true, and since you are using the same object in both drop-down lists, it is being marked as 'selected' in both.

我敢肯定,如果这是一个多选列表,无论是2和3将被作为'选择'标

I'm sure if this was a multi-select list, both "2" and "3" would be marked as 'selected'.

这篇关于下拉菜单充满了相同的列表项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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