CheckBoxList
CheckBoxList Example
Select items from the CheckBoxList.
@inherits ControlComponent
<p>Select items from the CheckBoxList.</p>
<asp.CheckBoxList @ref="this.checkboxlist"
AutoPostBack="true"
CellPadding="5"
CellSpacing="5"
RepeatColumns="2"
RepeatDirection="RepeatDirection.Vertical"
RepeatLayout="RepeatLayout.Flow"
TextAlign="TextAlign.Right"
OnSelectedIndexChanged="this.Check_Clicked">
<asp.ListItem>Item 1</asp.ListItem>
<asp.ListItem>Item 2</asp.ListItem>
<asp.ListItem>Item 3</asp.ListItem>
<asp.ListItem>Item 4</asp.ListItem>
<asp.ListItem>Item 5</asp.ListItem>
<asp.ListItem>Item 6</asp.ListItem>
</asp.CheckBoxList>
<br />
<br />
<asp.Label @ref="this.message" />
@code {
private CheckBoxList checkboxlist;
private Label message;
protected void Check_Clicked(object sender, EventArgs e)
{
message.Text = "Selected Item(s):<br /><br />";
// Iterate through the Items collection of the CheckBoxList
// control and display the selected items.
for (int i = 0; i < checkboxlist.Items.Count; i++)
{
if (checkboxlist.Items[i].Selected)
{
message.Text += checkboxlist.Items[i].Text + "<br />";
}
}
}
}
CheckBoxList Data Binding Example
Select items from the CheckBoxList.
@inherits ControlComponent
@inject HttpClient Http
<p>Select items from the CheckBoxList.</p>
<asp.CheckBoxList @ref="this.checkboxlist"
AutoPostBack="true"
DataSourceID="FreeDataSource1"
DataTextField="ColorTextField"
DataValueField="ColorValueField"
OnSelectedIndexChanged="this.Check_Clicked">
</asp.CheckBoxList>
<asp.FreeDataSource ID="FreeDataSource1" OnExecuteSelected="sender => this.colors" />
<br />
<br />
<asp.Label @ref="this.message" />
@code {
private Color[] colors;
private CheckBoxList checkboxlist;
private Label message;
protected override async Task OnInitializedAsync()
{
colors = await Http.GetFromJsonAsync<Color[]>("sample-data/colors.json");
}
protected void Check_Clicked(object sender, EventArgs e)
{
message.Text = "Selected Item(s):<br /><br />";
// Iterate through the Items collection of the CheckBoxList
// control and display the selected items.
for (int i = 0; i < checkboxlist.Items.Count; i++)
{
if (checkboxlist.Items[i].Selected)
{
message.Text += checkboxlist.Items[i].Text + "<br />";
}
}
}
public class Color
{
public string ColorTextField { get; set; }
public string ColorValueField { get; set; }
}
}
CheckBoxList Metadata
Name | Type | Kind | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
AccessKey | String | Parameter | ||||||||||||||||||
AppendDataBoundItems | Boolean | Parameter | ||||||||||||||||||
Attributes | IReadOnlyDictionary | Parameter | ||||||||||||||||||
AutoPostBack | Boolean | Parameter | ||||||||||||||||||
BackColor | String | Parameter | ||||||||||||||||||
BorderColor | String | Parameter | ||||||||||||||||||
BorderStyle | BorderStyle | Parameter | ||||||||||||||||||
BorderWidth | String | Parameter | ||||||||||||||||||
CausesValidation | Boolean | Parameter | ||||||||||||||||||
CellPadding | Int32 | Parameter | ||||||||||||||||||
CellSpacing | Int32 | Parameter | ||||||||||||||||||
ClientIDMode | ClientIDMode | Parameter | ||||||||||||||||||
CssClass | String | Parameter | ||||||||||||||||||
DataMember | String | Parameter | ||||||||||||||||||
DataSourceID | String | Parameter | ||||||||||||||||||
DataGroupField | String | Parameter | ||||||||||||||||||
DataGroupFormatString | String | Parameter | ||||||||||||||||||
DataTextField | String | Parameter | ||||||||||||||||||
DataTextFormatString | String | Parameter | ||||||||||||||||||
DataValueField | String | Parameter | ||||||||||||||||||
Enabled | Boolean | Parameter | ||||||||||||||||||
FontBold | Boolean | Parameter | ||||||||||||||||||
FontItalic | Boolean | Parameter | ||||||||||||||||||
FontNames | String | Parameter | ||||||||||||||||||
FontOverline | Boolean | Parameter | ||||||||||||||||||
FontSize | String | Parameter | ||||||||||||||||||
FontStrikeout | Boolean | Parameter | ||||||||||||||||||
FontUnderline | Boolean | Parameter | ||||||||||||||||||
ForeColor | String | Parameter | ||||||||||||||||||
Height | String | Parameter | ||||||||||||||||||
ID | String | Parameter | ||||||||||||||||||
LabelMode | LabelMode | Parameter | ||||||||||||||||||
RenderWhenDataEmpty | Boolean | Parameter | ||||||||||||||||||
RepeatColumns | Int32 | Parameter | ||||||||||||||||||
RepeatDirection | RepeatDirection | Parameter | ||||||||||||||||||
RepeatLayout | RepeatLayout | Parameter | ||||||||||||||||||
SelectedValue | String | Parameter | ||||||||||||||||||
SelectedValues | String[] | Parameter | ||||||||||||||||||
Style | String | Parameter | ||||||||||||||||||
TabIndex | Int16 | Parameter | ||||||||||||||||||
TextAlign | TextAlign | Parameter | ||||||||||||||||||
ToolTip | String | Parameter | ||||||||||||||||||
ValidationGroup | String | Parameter | ||||||||||||||||||
Visible | Boolean | Parameter | ||||||||||||||||||
Width | String | Parameter | ||||||||||||||||||
OnCallingDataMethods | CallingDataMethodsEventHandler | Event | ||||||||||||||||||
OnCreatingModelDataSource | CreatingModelDataSourceEventHandler | Event | ||||||||||||||||||
OnDataBinding | EventHandler | Event | ||||||||||||||||||
OnDataBound | EventHandler | Event | ||||||||||||||||||
OnDisposed | EventHandler | Event | ||||||||||||||||||
OnInit | EventHandler | Event | ||||||||||||||||||
OnLoad | EventHandler | Event | ||||||||||||||||||
OnPreRender | EventHandler | Event | ||||||||||||||||||
OnSelectedIndexChanged | EventHandler | Event | ||||||||||||||||||
OnTextChanged | EventHandler | Event | ||||||||||||||||||
OnUnload | EventHandler | Event | ||||||||||||||||||
ListItem | asp.ListItem | InnerProperty | ||||||||||||||||||
|