|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Announcements
Want a new Job?
Chapters
Services
Feature Zones
|
Note: This is an unedited contribution. If this article is inappropriate,
needs attention or copies someone else's work without reference then please
Report This Article
IntroductionI've recently noticed that many programmers miss functionality of option groups in .net framework select controls. After a while I decided to write my own control, that works similar to System.Web.UI.DropDownList control built in .net framework. My control is available for .net framework 2.0 or later. Background, W3 recommendationWhen working with DropDownGroupableList control, please keep in mind restrictions related to option groups and option items defined by w3 consorcium. See http://www.w3.org/TR/html4/interact/forms.html#h-17.6. Good website programmer is not defined only through effectivity of his program code :-) Data source typesData can be delivered in four different ways:
Provided data, declarative or manual through DataSource property, may be handled in normal way or hierarchically - read following paragraph. Hierarchical data source supportIf provided data source implements IHierarchicalEnumerable then DropDownGroupableList works little differently according to data processing. It is based on theory that option groups together with items represent some kind of two-level hierarchy. You can control hierarchical data processing by these settings:
Common propertiesIf you are experienced with System.Web.UI.WebControls.DropDownList control (and you should be when reading this article), you probably know its functionality and behavior. Here are listed some important and commonly used capabilities that my control has in common with standard DropDownList:
Differences against standard DropDownListSelectedValueWhen you set the value of property SelectedValue to value that corresponds to more than one item (e.g. you inserted more items with same value), then exception is thrown. ListItem.EnabledEnabled property of System.Web.UI.WebControls.ListItem class influences its visibility on page. I decided to change this behavior so setting this value to false makes it disabled via disabled html attribute but its still being rendered. Items collectionThis collection definition works with abstract OptionItemBase class that is implemented by OptionListItem and OptionGroupItem class. This enables my list control to contain option items as well as option groups at top level. OptionGroupItem class then may contain only OptionListItem class instances, no inner groups are allowed since it is not part of w3 recommendation. SamplesAttached zip file contains following sample pages:
ConclusionIt took me some noticeable time to create and debug this component so I hope its gonna be helpful for all asp.net programmers. Feel free to use it :-)
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||