Watch out !!! a bug in DropDownList
-
Hi, I wanted to highlight a bug in the Web-Control DropDownList. If it contains two or more items with different names, but with the same values, then it returns the SelectedIndex of the first item in the items array with the common value rather then the index of the chosen item. Bye
-
Hi, I wanted to highlight a bug in the Web-Control DropDownList. If it contains two or more items with different names, but with the same values, then it returns the SelectedIndex of the first item in the items array with the common value rather then the index of the chosen item. Bye
Hi there, I don't think this is a bug. As you may already know that the dropdownlist control at the client side is the
select
html element, when you submit the page, thevalue
(not thetext
) of the selectedoption
item of theselect
element is posted to the server. And at the server side, theSelectedIndex
property is set to the index of the item which is first found in the collection of the control based on theValue
property, not theText
property. So if there are more than one item that have the same value, you'll see that the first item in the collection is selected. -
Hi there, I don't think this is a bug. As you may already know that the dropdownlist control at the client side is the
select
html element, when you submit the page, thevalue
(not thetext
) of the selectedoption
item of theselect
element is posted to the server. And at the server side, theSelectedIndex
property is set to the index of the item which is first found in the collection of the control based on theValue
property, not theText
property. So if there are more than one item that have the same value, you'll see that the first item in the collection is selected.I disagree with you this time. Indeed you describe the procedure that happens. But I thought that ASP.NET should be Object Oriented. As far as I understand by a straightforward thinking, the SelectedIndex property should be as it sounds like, the index of the selected item. Apparently, the items are being represented to the user by the text property, not the values properties. Bye