ListBox
ListBox Example
@inherits ControlComponent
<asp.ListBox @ref="this.listBox"
Rows="6"
Width="100px"
SelectionMode="ListSelectionMode.Single">
<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.ListBox>
<br />
<br />
<asp.Button Text="Submit"
OnClick="this.SubmitBtn_Click" />
<asp.Label @ref="this.label"
FontNames="Verdana"
FontSize="10pt" />
@code {
private ListBox listBox;
private Label label;
protected void SubmitBtn_Click(object sender, EventArgs e)
{
if (listBox.SelectedIndex > -1)
label.Text = "You chose: " + listBox.SelectedItem.Text;
}
}
ListBox Multiple Selections Example
@inherits ControlComponent
<asp.ListBox @ref="this.listBox"
Rows="6"
Width="100px"
SelectionMode="ListSelectionMode.Multiple">
<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.ListBox>
<br />
<br />
<asp.Button Text="Submit"
OnClick="this.SubmitBtn_Click" />
<asp.Label @ref="this.label"
FontNames="Verdana"
FontSize="10pt" />
@code {
private ListBox listBox;
private Label label;
protected void SubmitBtn_Click(object sender, EventArgs e)
{
string msg = "";
foreach (ListItem li in listBox.Items)
{
if (li.Selected == true)
{
msg += "<br>" + li.Text + " is selected.";
}
}
label.Text = msg;
}
}
ListBox Data Binding Example
@using System.Collections
@inherits ControlComponent
<asp.ListBox @ref="this.listBox"
DataSourceID="FreeDataSource1"
Width="100px">
</asp.ListBox>
<asp.FreeDataSource ID="FreeDataSource1" OnExecuteSelected="sender => this.CreateDataSource()" />
<br />
<br />
<asp.Button Text="Submit"
OnClick="this.SubmitBtn_Click" />
<asp.Label @ref="this.label"
FontNames="Verdana"
FontSize="10pt" />
@code {
private ListBox listBox;
private Label label;
protected ICollection CreateDataSource()
{
ArrayList values = new ArrayList();
values.Add("Item 1");
values.Add("Item 2");
values.Add("Item 3");
values.Add("Item 4");
values.Add("Item 5");
values.Add("Item 6");
return values;
}
protected void SubmitBtn_Click(object sender, EventArgs e)
{
if (listBox.SelectedIndex > -1)
label.Text = "You chose: " + listBox.SelectedItem.Text;
}
}
ListBox 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 | ||||||||||||||||||
| 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 | ||||||||||||||||||
| Rows | Int32 | Parameter | ||||||||||||||||||
| SelectedValue | String | Parameter | ||||||||||||||||||
| SelectedValues | String[] | Parameter | ||||||||||||||||||
| SelectionMode | ListSelectionMode | Parameter | ||||||||||||||||||
| Style | String | Parameter | ||||||||||||||||||
| TabIndex | Int16 | 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 | ||||||||||||||||||
|
||||||||||||||||||||