组合框重复值 [英] Combo box duplicate values

查看:66
本文介绍了组合框重复值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个组合框,在其中填充一个文本值,该值在内部与唯一ID相关联.但是文本值可以重复.假设我的组合有"AA",然后是"AA".第一个"AA"内部绑定到ID-1,第二个"AA"绑定到ID-2.我的问题是,当我选择第二个"AA"并再次单击组合的下拉箭头时,默认情况下会选择第一个"AA" ".但是我想选择第二个"AA".

I have a combo box in which i am populating a text value which is associated internally with unique ID. But the text value could be repeated. Say my combo has "AA" followed by "AA". The first "AA" is internally bound to ID - 1 and second "AA" to ID-2.My problem is when I select second "AA" and again click on drop down arrow of combo, by default it selects the first "AA". But I want second "AA" to be selected.

推荐答案

哦,这是重复文本组合框中的问题,已经讨论了很多次,请参见此处 [
Oh thats problem in combobox with duplicate text, it''s discussed quite few time, see HERE[^].

The ASP.NET ComboBox is using the item value as an identity property for selected item. This is by design. for good practice Avoid using items with duplicate values.


组合框具有一个称为DisplayMember的属性,您可以在其中指定数据源显示的值.

您知道了吗?
The combobox have a Property Called DisplayMember in that you specify what value of datasource shows.

Did you inform it?


您可以使用
You can use
ComboBox1.SelectedValue = 1; //instead of SelectedText



谢谢,
Imdadhusen



Thanks,
Imdadhusen


这篇关于组合框重复值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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