Last post Sep 01, 2008 02:40 PM by RichardD
Jan 30, 2008 10:34 AM|ddelella|LINK
The ListBox control has been a part of the WebControls class since .NET Framework 1.1. We are now on 3.5 and we still have only seen minimal useful changes to this control. The biggest reason why people create custom controls is because the base control
does not render a feature correctly or at all. These should be hints on what features need to be added for the future. My biggest complaint about the ListBox control is the lack of border support. The methods for BorderColor, BorderWidth, and BorderStyle
existed in 1.1, removed in 2.0, readded in 3.0 - 3.5. However, in all versions of the framework those methods, even though they exist, do not control any functionality. Even on the MSDN website they specify in the remarks that the method is inherited from
the Control class and does not apply to the ListBox. I would like call BS on this one. As determined by several custom components for the ListBox, these properties are used but not rendered by the ListBox control. If they rendered the control properly these
methods would regain their use and allow a more customized skinning. Prime example of how the ListBox properties can be modified to be rendered correctly is seen here:
I say to Microsoft, if a method is not in use by the control, DO NOT LIST IT. This will avoid confusion. That is the reason why 2.0 was an improvement since it actually did not display these methods as usable for the ListBox. Why they were readded for
3.0 I have no idea. For all those who agree this should be added to framework as normal functionality please speak up and maybe we can finally be heard. There are plenty of posts out there looking to achieve this functionality.
Feb 04, 2008 09:51 AM|ddelella|LINK
More complaints to be added to the list:
1. PostBack is attempting to load the SelectedIndex based on the value. A true ListBox should load based on the actual SelectedIndex NOT the value. Prime example why this loading method fails:
I have a office locations list. Each location in the database is based on two primary keys, LocationID and SiteID. Since there is no way to concatinate fields into the value of a databound list I was stuck with using the LocationID as the value and the
SiteID as the description. The locations are usually ID 1 or 2. Whenever, the ListBox reloads the first value index of 1 or 2 is always selected despite what index was last chosen. If the ListBox loaded the last index selected then it would be able to have
multiple options with the same value.
Correction to the border complaint:
the borders in the CheckBoxList can be turned on/off using the properties, the same functionality should be applied to the borders of the ListBox control.
Feb 04, 2008 07:49 PM|PLBlum|LINK
I believe that the problem with borders is due to Internet Explorer limitations. Until IE 7, that browser didn't support styles for borders correctly. It should work in IE 7 and FireFox, thus the properties make sense.
Keep in mind that the actual ListBox control merely creates the HTML <select> tag. When you want more features than are supported by the <select> tag, an entirely different control must be created. The DataList control and GridView may be more useful for
problem, they probably won't be attempting to create something as feature rich as users want. I encourage you to evaluate the available third party controls.
Feb 25, 2008 04:34 PM|ddelella|LINK
The actual problem is the way the tag is created via the .NET framework when it is rendered. I have tried this tag in IE6, IE7, FireFox, and Safari. The reason that I am a big advocate of this being able to work is that they already have shown us that
they know how to make it work. Create a CheckListBox and remove the border. Same concept accept without the check boxes being rendered at the beginning of each line. This should not be a hard thing to fix but I feel that Microsoft is going by the "not many
people are complaining, lets not fix it" policy. I have tried all the latest .NET frameworks (up to 3.5) and still there is no fix for making this property rendered properly.
In response to third party controls, I am developing for a company who does not feel like paying for 3rd party controls to handle a simple UI enhancement. They have accepted the fact that it will not work and we have found an alternative look and feel.
We have continued to use CheckListBoxes for their ability to remove the border. I still think Microsoft, who preaches better UI features for the web in each version of .NET should revisit the code for the ListBox and compare it to the rendering of the CheckListBox
and figure out what needs to be corrected to make the property work, or just remove the properties once and for all (like .NET 2.0).
Aug 03, 2008 08:12 AM|windchaser|LINK
ddelella, can you post the code you used to change the boarder style of the listbox control?
Sep 01, 2008 02:40 PM|RichardD|LINK
The ListBox / DropDownList controls cannot load the selected item based on index, because that isn't how the HTML SELECT element works. The posted data is the value of the selected item, not the index. The only way to pass the index is to use an extra hidden
field and some script, in which case the control will be unusable when script is disabled.
However, the option to specify multiple data fields and a format string for the value and text would be nice.