The ListControl Family of Controls

\QCubed\Control\ListControl controls handle simple lists of objects which can be selected. In its most basic form, we are talking about HTML listboxes (e.g. <select>) with name/value pairs (e.g. <option>).

Of course, list boxes can be single- and multi-select. But keep in mind that sometimes you may want to display that list as a list of labeled checkboxes (which essentially works like a multi-select list box) or as a list of labeled radio buttons (which works like a single-select list box). QCubed includes the ListBox, CheckboxList, and RadioButtonList controls, all of which inherited from ListControl to allow you to present the data and functionality you need in the most user-friendly way.

In this example, we create a ListBox and Checkbox control. They pull their data from the Person table in the database. Also, if you select a person, we will update the lblMessage label to show what you have selected.

If you do a View Source... in your browser to view the HTML, you'll note that the value attributes in the <option> tags are indexes (starting with 0) and not the values assigned in the PHP code. This is done intentionally as a security measure to prevent database indexes from being sent to the browser, and to allow for non-string-based values, or even duplicate values. You can look up specific values in the ListControl by using the SelectedValue attribute. You can also look up selected Names, Ids, and get the whole ListItem.

Projects and Their Members

The second list demonstrates how you can use optgroup labels to visually group related list items together in a ListBox. Here, we pull a list of projects from the database and show each project's team members as selectable items, grouped under their respective project names. This allows for better organization and a more intuitive interface when dealing with categorized data.

Each list item still uses the person ID as the value, and when a selection is made, the corresponding name is displayed. You could easily extend this to show additional project or person details.

Recently Selected: <None>