|
| 1 | +# CheckBoxList |
| 2 | + |
| 3 | +The CheckBoxList component renders a group of checkboxes, allowing users to select multiple items from a list. It supports both static items and data-bound scenarios. |
| 4 | + |
| 5 | +Original Web Forms documentation: https://docs.microsoft.com/en-us/dotnet/api/system.web.ui.webcontrols.checkboxlist?view=netframework-4.8 |
| 6 | + |
| 7 | +!!! warning "Not Yet Implemented" |
| 8 | + This component is not yet available in BlazorWebFormsComponents. This documentation is a placeholder for the planned implementation. |
| 9 | + |
| 10 | +## Planned Features |
| 11 | + |
| 12 | +- Static items via `StaticItems` parameter with `ListItem` collection |
| 13 | +- Data binding via `Items` parameter with `DataTextField` and `DataValueField` |
| 14 | +- Multiple selection tracking via `SelectedItems` or `SelectedValues` |
| 15 | +- `RepeatColumns` for multi-column layout |
| 16 | +- `RepeatDirection` (Vertical or Horizontal) |
| 17 | +- `RepeatLayout` (Table, Flow, OrderedList, UnorderedList) |
| 18 | +- `TextAlign` for label positioning (Left or Right) |
| 19 | +- `OnSelectedIndexChanged` event handler |
| 20 | +- Style attributes and CssClass formatting |
| 21 | + |
| 22 | +## Web Forms Declarative Syntax |
| 23 | + |
| 24 | +```html |
| 25 | +<asp:CheckBoxList |
| 26 | + AccessKey="string" |
| 27 | + AutoPostBack="True|False" |
| 28 | + BackColor="color name|#dddddd" |
| 29 | + BorderColor="color name|#dddddd" |
| 30 | + BorderStyle="NotSet|None|Dotted|Dashed|Solid|Double|Groove|Ridge|Inset|Outset" |
| 31 | + BorderWidth="size" |
| 32 | + CellPadding="integer" |
| 33 | + CellSpacing="integer" |
| 34 | + CssClass="string" |
| 35 | + DataSourceID="string" |
| 36 | + DataTextField="string" |
| 37 | + DataValueField="string" |
| 38 | + Enabled="True|False" |
| 39 | + EnableTheming="True|False" |
| 40 | + EnableViewState="True|False" |
| 41 | + Font-Bold="True|False" |
| 42 | + Font-Italic="True|False" |
| 43 | + Font-Names="string" |
| 44 | + Font-Overline="True|False" |
| 45 | + Font-Size="string|Smaller|Larger|XX-Small|X-Small|Small|Medium|Large|X-Large|XX-Large" |
| 46 | + Font-Strikeout="True|False" |
| 47 | + Font-Underline="True|False" |
| 48 | + ForeColor="color name|#dddddd" |
| 49 | + Height="size" |
| 50 | + ID="string" |
| 51 | + OnDataBinding="DataBinding event handler" |
| 52 | + OnDisposed="Disposed event handler" |
| 53 | + OnInit="Init event handler" |
| 54 | + OnLoad="Load event handler" |
| 55 | + OnPreRender="PreRender event handler" |
| 56 | + OnSelectedIndexChanged="SelectedIndexChanged event handler" |
| 57 | + OnUnload="Unload event handler" |
| 58 | + RepeatColumns="integer" |
| 59 | + RepeatDirection="Horizontal|Vertical" |
| 60 | + RepeatLayout="Table|Flow|OrderedList|UnorderedList" |
| 61 | + runat="server" |
| 62 | + SelectedIndex="integer" |
| 63 | + SelectedValue="string" |
| 64 | + TabIndex="integer" |
| 65 | + TextAlign="Left|Right" |
| 66 | + ToolTip="string" |
| 67 | + Visible="True|False" |
| 68 | + Width="size"> |
| 69 | + |
| 70 | + <asp:ListItem Value="value1" Text="Display Text 1" Selected="True|False" /> |
| 71 | + <asp:ListItem Value="value2" Text="Display Text 2" /> |
| 72 | + |
| 73 | +</asp:CheckBoxList> |
| 74 | +``` |
| 75 | + |
| 76 | +## Proposed Blazor Syntax |
| 77 | + |
| 78 | +### Basic Usage |
| 79 | + |
| 80 | +```razor |
| 81 | +<CheckBoxList TItem="object" |
| 82 | + StaticItems="items" |
| 83 | + OnSelectedIndexChanged="HandleSelectionChanged" /> |
| 84 | +
|
| 85 | +@code { |
| 86 | + private ListItemCollection items = new() |
| 87 | + { |
| 88 | + new ListItem("Option One", "1"), |
| 89 | + new ListItem("Option Two", "2"), |
| 90 | + new ListItem("Option Three", "3") |
| 91 | + }; |
| 92 | + |
| 93 | + private void HandleSelectionChanged() |
| 94 | + { |
| 95 | + // Handle selection change |
| 96 | + } |
| 97 | +} |
| 98 | +``` |
| 99 | + |
| 100 | +### Multi-Column Layout |
| 101 | + |
| 102 | +```razor |
| 103 | +<CheckBoxList TItem="object" |
| 104 | + StaticItems="items" |
| 105 | + RepeatColumns="3" |
| 106 | + RepeatDirection="RepeatDirection.Horizontal" /> |
| 107 | +``` |
| 108 | + |
| 109 | +### Data Binding |
| 110 | + |
| 111 | +```razor |
| 112 | +<CheckBoxList TItem="Category" |
| 113 | + Items="categories" |
| 114 | + DataTextField="Name" |
| 115 | + DataValueField="Id" /> |
| 116 | +
|
| 117 | +@code { |
| 118 | + private List<Category> categories = new() |
| 119 | + { |
| 120 | + new Category { Id = "1", Name = "Electronics" }, |
| 121 | + new Category { Id = "2", Name = "Clothing" }, |
| 122 | + new Category { Id = "3", Name = "Books" } |
| 123 | + }; |
| 124 | + |
| 125 | + public class Category |
| 126 | + { |
| 127 | + public string Id { get; set; } |
| 128 | + public string Name { get; set; } |
| 129 | + } |
| 130 | +} |
| 131 | +``` |
| 132 | + |
| 133 | +### Getting Selected Items |
| 134 | + |
| 135 | +```razor |
| 136 | +<CheckBoxList @ref="checkboxList" TItem="object" StaticItems="items" /> |
| 137 | +<Button Text="Submit" OnClick="HandleSubmit" /> |
| 138 | +
|
| 139 | +@code { |
| 140 | + private CheckBoxList<object> checkboxList; |
| 141 | + |
| 142 | + private void HandleSubmit() |
| 143 | + { |
| 144 | + var selectedItems = checkboxList.SelectedItems; |
| 145 | + foreach (var item in selectedItems) |
| 146 | + { |
| 147 | + Console.WriteLine($"Selected: {item.Text} ({item.Value})"); |
| 148 | + } |
| 149 | + } |
| 150 | +} |
| 151 | +``` |
| 152 | + |
| 153 | +## Contributing |
| 154 | + |
| 155 | +If you would like to help implement this component, please see our [contributing guide](https://github.com/FritzAndFriends/BlazorWebFormsComponents/blob/dev/CONTRIBUTING.md). |
| 156 | + |
| 157 | +## See Also |
| 158 | + |
| 159 | +- [CheckBox](CheckBox.md) - Single checkbox control |
| 160 | +- [RadioButtonList](RadioButtonList.md) - Radio button selection list |
| 161 | +- [DropDownList](DropDownList.md) - Single selection dropdown |
| 162 | +- [ListBox](ListBox.md) - Multiple selection list control |
0 commit comments