ASP.NET ListItemControl


Web Server ControlsWeb Server Controls

Definition and Usage

The ListItem control can create an item in a list.

This control is used together with the following list controls:<asp:ListBox>、 <asp:RadioButtonList>and<asp:BulletedList>。


Syntax

<asp:ListItem
Enabled="True|False"
Selected="True|False"
Text="label"
Value="value" />

Properties

Properties Description .NET
Attributes Optional. A collection of attribute name/value pairs for the ListItem that are not directly supported by this class. 1.0
Enabled Optional. Specifies whether the item is disabled or enabled. 2.0
Selected Optional. Specifies whether the item is selected. 1.0
Text Optional. The text displayed in the ListItem. 1.0
Value Optional. The value of the ListItem. 1.0

Web Control Standard Properties

AccessKey, Attributes, BackColor, BorderColor, BorderStyle, BorderWidth, CssClass, Enabled, Font, EnableTheming, ForeColor, Height, IsEnabled, SkinID, Style, TabIndex, ToolTip, Width

For a full description, visitWeb Control Standard Properties。

Control Standard Properties

AppRelativeTemplateSourceDirectory, BindingContainer, ClientID, Controls, EnableTheming, EnableViewState, ID, NamingContainer, Page, Parent, Site, TemplateControl, TemplateSourceDirectory, UniqueID, Visible

For a full description, visitControl Standard Properties。

It is possible to use the Text or Value property as well as inner HTML text to set the text displayed for the list item.

Examples

<asp:ListItem Value="Text1" Text="Text2">Text3</asp:ListItem>

Depending on the combination of the Text or Value property and the inner HTML text, different text can be displayed and different values can be used. The following table lists all possible combinations and their results:

Inner HTML Text Property Value Property Text displayed Value used
Set Set Set Inner HTML Value Property
Set Set Not set Inner HTML Inner HTML
Set Not set Set Inner HTML Value Property
Set Not set Not set Inner HTML Inner HTML
Not set Set Set Text Property Value Property
Not set Set Not set Text Property Text Property
Not set Not set Set Value Property Value Property
Not set Not set Not set Not set Not set


Tips and Notes

Note:Because both the Text and Value properties have an empty string as their default value, list controls may contain empty list items.


Examples

BulletedList with basic ListItem
This example demonstrates a BulletedList control with two ListItems in an .aspx file.

ListBox with ListItems with different properties
This example demonstrates a ListBox control with several ListItems in an .aspx file. The items in the list use different properties to display the text of the ListItem.

ListBox with a disabled ListItem
This example shows a ListBox control with a disabled ListItem.

RadioButtonList with a selected ListItem
This example shows a RadioButtonList control with a selected ListItem.


Web Server ControlsWeb Server Controls Other Extensions